Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to programmatically access Download folder on Android Q (SDK >= 29)?

I want to list all files .txt in the Download folder and then allow the user to pick one and read its content. My minSdkVersion is 16, but I came across this problem because my Android is Q (29).

What I tried:

Apparently Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) would solve it for SDK <= 29. However, I didn't test it because I would first like to check out a solution for Android Q.

getExternalStoragePublicDirectory says:

When an app targets Build.VERSION_CODES.Q, the path returned from this method is no longer directly accessible to apps. Apps can continue to access content stored on shared/external storage by migrating to alternatives such as Context#getExternalFilesDir(String), MediaStore, or Intent#ACTION_OPEN_DOCUMENT.

So:

  • getExternalFilesDir returns /storage/emulated/0/Android/data/com.mypackage/files/Download. This path is not useful, I expected it to return /storage/emulated/0/Download, which is where the downloaded files are.

  • I didn't manage to do something with MediaStore.Downloads. I checked the documentation and it says "In particular, if your app wants to access a file within the MediaStore.Downloads collection that your app didn't create, you must use the Storage Access Framework.". So, I assume it won't work for me.

  • In my concept, Intent and Storage Access Framework would need the user to navigate through directories and files using a File Manager, which is not what I want here.

In short:

Is it possible to list the .txt downloaded files programmatically in Android Q (SDK >= 29)? If so, how?

like image 484
Rafael Tavares Avatar asked Feb 26 '20 14:02

Rafael Tavares


People also ask

How do I find my Download folder on Android?

Tap the hamburger menu icon in the top-left corner to open the side menu. Select the “Downloads” option from the list. All of your downloaded files can be found in this folder.

Where is the Download folder in Android 11?

Look in the Downloads Folder The native app can vary based on the manufacturer or even your mobile carrier. On stock Android, this app is just called “Files.” Simply open it then tap “Downloads” to access the Downloads folder. Your downloaded files should be listed, with the most recent one at the top.

How do I Download files on Android?

Go to the webpage where you want to download a file. Touch and hold what you want to download, then tap Download link or Download image. To see all the files you've downloaded to your device, open the Downloads app. Learn more about managing downloaded files.


1 Answers

Is it possible to list the .txt downloaded files programmatically in Android Q (SDK >= 29)?

Not ones created by other apps, which would appear to be your intention.

The closest is if you use ACTION_OPEN_DOCUMENT_TREE and ask the user to open the Downloads/ tree on external storage... and you cannot do that on Android R (at least through DP1).

like image 89
CommonsWare Avatar answered Oct 16 '22 16:10

CommonsWare