在 /Download 下保存文件,名称为 /storage/emulated/0/Download。有时文件不可访问

Saving file under /Download gives name /storage/emulated/0/Download. Sometimes the file is not accessable

在我的三星设备上,我在 /Download 文件夹中放置了一个文件。当我 select 我的应用程序中的文件(通过文件浏览器)时,该文件被称为 /storage/emulated/0/Download/myfile.db。此名称存储在我的应用程序设置中。

在应用程序启动时,文件应该被打开。首先,应用程序检查文件是否存在。在某些情况下,比如每 2 周一次,据说该文件不存在!半年以来,这也发生在我的朋友手机上。

为什么会这样?多年来,一切 运行 都很顺利。

这段代码运行了 6 年。当然我添加了权限的东西。

非常感谢您的帮助!

您不能将 下载 用作文件的保证存储位置。您应该为应用程序使用 Internal 存储。这是 Google 写的关于下载文件夹的内容:

This space is called external because it's not guaranteed to be accessible—it is a storage space that users can mount to a computer as an external storage device, and it might even be physically removable.

Here you can read 更多关于 Internal 存储和 External 存储在 Android 中。

Here is some more information 关于 从 Google 下载 文件夹。

Caution: The external storage might become unavailable if the user removes the SD card or connects the device to a computer. And the files are still visible to the user and other apps that have the READ_EXTERNAL_STORAGE permission. So if your app's functionality depends on these files or you need to completely restrict access, you should instead write your files to the internal storage.