Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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 from their download folder. 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.

On https://developer.android.com/training/data-storage/shared/documents-files#grant-access-directory

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.

https://developer.android.com/about/versions/10/privacy/changes

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().
  • https://developer.android.com/about/versions/11/privacy/storage

    (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.

    I'm confused. You've mentioned quite a few things about whole directory access , but you don't seem to want whole directory access, you just want users to be able to select a zip file they downloaded / have available on Google Drive / whatever? ianhanniballake Jul 20, 2021 at 18:23 How it now works in the app is that they select their file from a directory list to import. That way you stay inside the app, the only other way I think how it can be done is if open a 'explorer' app and from there 'share' the file into the app. I think this might be more difficult for people to do. It would require way more changes to my code, so that's an extra downside for me, but if that's the only way, then this would also be an option. Julius Jul 20, 2021 at 20:26 Use ACTION_OPEN_DOCUMENT / ActivityResultContracts.OpenDocument to let the user pick the ZIP to import. Use ACTION_CREATE_DOCUMENT / ActivityResultContracts.CreateDocument to let the user pick where to write the ZIP for export. For import, you probably need to copy the ZIP to some file that you control (e.g., in getCacheDir() ), unZIP it, then delete the copy. Similarly, for export, you probably need to create the ZIP as a file, then copy it to the user's desired location, then delete the original. The ZIP APIs might be able to be used directly without copies, but I'm not 100% certain. CommonsWare Jul 20, 2021 at 20:46 Thanks @CommonsWare for pointing me in that direction. I guess my current in-app-file-selection is no longer supported. Not super happy to have to write extra code (for no new features), but I am happy for your quick response. The export already works, but I much appreciate you have taken the time :). Julius Jul 20, 2021 at 21:07

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question . Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers .