androidstorage-access-frameworkdocuments-provider

Android Documents Provider how to use and do I need it?


I'm going to create an app for accessing the files from the Internet. I do not want to implement UI, but instead to make them visible from other file managers. So, I chose to implement a Document Provider. And I did it. On the next pictures you can see that I open "Files" app, find "My document provider" and can access its files.

enter image description here enter image description here enter image description here

However, it's an emulator. When I tried to use the app on my physical device I found that I have no ways to see document providers. I use Xiaomi Redmi Note 5 Pro (android 9.0) there is no "Files" app. I tested top ~20 File Managers from Google Play and even MIUI build in file-explorer, but none of them can show me my "My document provider".

I managed to see my documents provider only when tried to attach a document from Gmail app. But it's not what I need.

Questions:

  1. am I right that Documents Provider is not what I need?
  2. Am I right it's rather an ADDITIONAL way to share the files with other client apps which use Storage Access Framework (like Gmail, photo editor, etc), but was not designed to be used as the main method for accessing the files?
  3. Am I right that I have to implement my own Activities with UI and full functionality of file explorer as a main approach for user to access his files? (like Google Drive app - it has both: own UI for managing the files and documents provider accessible from system picker)

UPDATED

Finally I've found a solution. As I understand standard application "Files" is build in to ANY device. However, probably, manufacturer "hides" this app and provides some analog. On MIUI it's some "File Manager". On many Samsung devices, as well as on Pixel 2 XL, it's "Google Files" app. None of them see document providers. Only "Files" app can.

The "Files" app is still accessible as an option when you use SAF (for example start an Intent with ACTION_OPEN_DOCUMENT). But still you are not able to launch that app standalone. However, you can download "Files shortcut" from Google Play. When open it, you can choose an app for which "Files shortcut" should work as a shortcut. I chose "Files" app and everything works (didn't work until I checked "remember my choice" option). On both, Pixel 2 and Redmi Note 5 I can see my document providers. It's a great news, since I do not have to waste time for creating UI!

P.S. Please note, what I described above is not taken from a reliable source. I used the phrase "hidden app" and the fact about pre installed "Files" on ANY device just based on my observation and understanding.

P.P.S Also, I found that on Pixel 2 in "Google files" app there is also a way to open "Files": Browse -> Other storage -> System traces. For some reason there is no "Other storage" button on Redmi Note 5.


Solution

  • I do not want to implement UI, but instead to make them visible from other file managers

    You have no means of forcing other apps to do much of anything. In particular, you have no means of forcing a file manager to show things from your app.

    Am I right it's rather an ADDITIONAL way to share the files with other client apps which use Storage Access Framework (like Gmail, photo editor, etc), but was not designed to be used as the main method for accessing the files?

    Correct. A DocumentsProvider is for making documents available via the Storage Access Framework. A file manager could elect to show documents from the registered DocumentsProvider implementations on the device. In practice, I am not surprised that few file managers do this. You might consider contributing that feature to open source file managers.

    Am I right that I have to implement my own Activities with UI and full functionality of file explorer as a main approach for user to access his files?

    That is up to you. If you want your app to be guaranteed to do something for all of your users, having your own UI for traversing your collection of documents would be a good idea.