分区存储 - 下载文件夹访问
Scoped Storage - Download folder access
我的目标是 android 10,我不使用 android:requestLegacyExternalStorage
。我使用 DownloadManager
通过 request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName)
下载到下载文件夹。我收听下载完成广播,提取 uri (file:///storage/emulated/0/Download/<name>.pdf
) 并通过 FileProvider
在 pdf-reader 中打开它。它有效……为什么?自 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 10,我不使用 android:requestLegacyExternalStorage
。我使用 DownloadManager
通过 request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName)
下载到下载文件夹。我收听下载完成广播,提取 uri (file:///storage/emulated/0/Download/<name>.pdf
) 并通过 FileProvider
在 pdf-reader 中打开它。它有效……为什么?自 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