0

I have a backup restore app on Google Play. Currently, it allows backing up things on the storage returned by Environment.getExternalStorageDirectory().

But, I want to let the users choose a backup directory, whether it be on SD card, internal storage or USB drive. Then, I want to save its path in shared preferences and save backups in it whenever user creates a new backup.

How do I get a list of all storages and ask a one time permission to write to them whenever I want?

whiteShadoww
  • 81
  • 1
  • 9
  • Use `ACTION_OPEN_DOCUMENT_TREE`, from the Storage Access Framework. This works with documents and `Uri` values, not directories and paths, but the core concept is the same. And, you do not have access to arbitrary locations on external and removable storage on Android Q (by default) and Android R+ (for all apps). – CommonsWare Jul 14 '19 at 16:17
  • @CommonsWare so, in Android Q, the only directory that I have access to is storage/Android/data/my app and files in MediaStore? – whiteShadoww Jul 14 '19 at 17:11
  • I would phrase it as "content in `MediaStore`", since you will not have filesystem access to media either. The only filesystem access you have is to `getExternalFilesDirs()`, `getExternalCacheDirs()`, and `getExternalMediaDirs()`, all of which are in `Android/data/.../`, where `...` is your application ID. Through the Storage Access Framework and `MediaStore` you can access more content, but it is via `Uri` objects and `ContentResolver`, not filesystem APIs like `File`. – CommonsWare Jul 14 '19 at 17:47

0 Answers0