Search code examples
androidandroid-download-managerstorage-access-frameworkandroid-10.0scoped-storage

Scoped Storage - Download folder access


I am targeting android 10 and I don't use android:requestLegacyExternalStorage. I use the DownloadManager to download into the download folder via: request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName). I listen to the download-complete-broadcast, extract the uri (file:///storage/emulated/0/Download/<name>.pdf) and open it in a pdf-reader via FileProvider. It works... why? Isn't it supposed to NOT work since android 10 and scoped storage? Why am I allowed to access files in the download-folder?

EDIT: Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).listFiles() lists all Files although the doc says:

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


Solution

  • This was the solution:

    If an app is installed with legacy external storage enabled, the app remains in this mode until it's uninstalled.

    Changing the flag and restarting the app does not work.

    Edit: Since a source was requested. The page changed since when I saw it first, so the quote is not 100% correct anymore, but still: In the blue box