我的目标是 android 10,我不使用 android:requestLegacyExternalStorage
.我用 DownloadManager
通过以下方式下载到下载文件夹:request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName)
.我收听下载完成广播,提取 uri ( file:///storage/emulated/0/Download/<name>.pdf
) 并通过 FileProvider
在 pdf 阅读器中打开它.它有效……为什么?自 android 10 和范围存储以来,它不应该工作吗?为什么允许我访问下载文件夹中的文件?
编辑:Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).listFiles()
列出所有文件,尽管文档说:
To improve user privacy, direct access to shared/external storage devices is deprecated. When an app targets Q, the path returned from this method is no longer directly accessible to apps
最佳答案
这是解决方案:
If an app is installed with legacy external storage enabled, the app remains in this mode until it's uninstalled.
更改标志并重新启动应用程序不起作用。
编辑:由于请求了来源。自从我第一次看到它以来,页面发生了变化,所以引用不再是 100% 正确,但仍然是:In the blue box
关于android - 分区存储 - 下载文件夹访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57977190/