Search code examples
androidandroid-permissionsandroid-10.0

With Scoped Storage introduced in Android Q, how am I supposed to develop a file manager app?


Android Q will introduce a new sandboxed filesystem for apps, Scoped Storage. This policy will be enforced on any apps targeting API>=29. How should a thrid-party file manager app get through this restriction and continue to work properly?

This question is meant to be generic for any apps that have some file-managing functionalities, like browsing, saving, loading, syncing, etc.


Solution

  • I believe your question is equivalent to: How app can get access to main phone storage (usually /sdcard)?

    The answer is: ask user for access to the whole /sdcard using ACTION_OPEN_DOCUMENT_TREE action. That way your app can access /sdcard and all its subdirectories.

    From https://developer.android.com/preview/privacy/scoped-storage#manage-groups-of-files :

    File management and media creation apps typically manage groups of files in a directory hierarchy. These apps can invoke the ACTION_OPEN_DOCUMENT_TREE intent to allow the user to grant access to an entire directory tree. Such an app would be able to edit any file in the selected directory, as well as any of its sub-directories.

    Using this interface, users can access files from any installed instance of DocumentsProvider, which any locally-backed or cloud-based solution can support.

    There is also sample project on Github showing how it is done: https://github.com/android/storage/tree/228c8e0aa19586bfcf36318ddb191719537a45a4/ActionOpenDocumentTree

    That's what "Files by Google" is currently doing on Android Q beta: https://www.androidpolice.com/2019/04/08/scoped-storage-in-android-q-beta-2-limits-how-apps-can-access-files/#1