How can I let Android 10+ users import a zip file from their download folder in my app?

My ideas app does not have an online back-end, so users can export a zip file to backup/transport their ideas. Then on their other (new) device, they could import the zip file. Inside the app the zip file is extracted and the content (text, audio, images) recreated.

Since Android 10 (and beyond) the way files and permission works is different.


it says:

When using ACTION_OPEN_DOCUMENT_TREE, your app gains access only to the files in the directory that the user selects.

On Android 11 (API level 30) and higher, you cannot use the ACTION_OPEN_DOCUMENT_TREE intent action to request access to [...] the Download directory.

By default, apps targeting Android 10 and higher are given scoped access into external storage, or scoped storage. Such apps can see the following types of files within an external storage device without needing to request any storage-related user permissions:

  • Files in the app-specific directory, accessed using getExternalFilesDir().
  • Photos, videos, and audio clips that the app created from the media store.

(as far as I can tell, the same rules as for 10 regarding my issue)

Since my files are not media files, it doesn't seem to be possible to let users select the file from a list.

I actually thought my current solution (file chooser, pointing to Environment.getExternalStorageDirectory()) was working, since it worked in emulator. But today I got a new device with Android 10 and it failed.

I find it very hard to find an answer to this question, because the search words and documentation all resolve around media files (images mostly).

Any way the user could import the zip file will do. But it is quite difficult for a normal user to move a downloaded / USB transfered file first into an app specific folders or something like that.

Read more here:

Content Attribution

This content was originally published by JULIUS at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: