2

I have an app that downloads files and stores them in a folder in external storage. I would like to be able to open the built-in Android file manager app to show my folder to the user. Once the file manager opens, I want the file manager to behave as if the user started the file manager by tapping the icon on the home screen. That is the user should be able to copy, move, and rename files as he or she pleases. If the user taps on a file, the file manager should try to find some app that can open this file. This is the same user experience as starting the file manager manually.

I found many questions on StackOverflow, which deal with opening the file manager, but none of them fit my use case.

  1. ACTION_GET_CONTENT is commonly recommended. For example here Open folder content with default file manager in android and many others. This does not work for my use case, because it brings up a file picker and passes control back to my app as soon as the user taps any file. I want user tapping on a file to have the same effect as if they opened the file manager manually (without my app), browsed to the file and tapped it.

  2. I do not want to make the user select which file manager to use. I always want to open the built-in file manager, which is available on all Android devices since Nougat (https://android.googlesource.com/platform/frameworks/base/+/008e948/packages/DocumentsUI/src/com/android/documentsui/FilesActivity.java). If the device vendor or the user somehow uninstalls this file manager, I am fine with the operation failing. I do not want to complicate user experience by making them select which file manager to use.

George
  • 2,436
  • 4
  • 15
  • 30
  • Call [`getLaunchIntentForPackage()` on `PackageManager`](https://developer.android.com/reference/android/content/pm/PackageManager#getLaunchIntentForPackage(java.lang.String)) for your desired application ID. Note that you will need to deal with package visibility rules on Android 11+. – CommonsWare Oct 23 '21 at 18:09
  • Thank you, @CommonsWare. GetLaunchIntentForPackage("com.android.documentsui") return null. Calling it with package names for regular apps (like "com.chess") returns an Intent. I am testing with Android 8. – George Oct 23 '21 at 19:23
  • On that device, is there a "Files" launcher icon? If the answer is yes, tap it and see what Logcat reports is being started. On a Pixel 5 running Android 12, that is from `com.google.android.apps.nbu.files`, not `com.android.documentsui`. I too get `null` for `getLaunchIntentForPackage("com.android.documentsui")`. But, for example, on a Galaxy S9, neither of those packages have launcher activities, and the only built-in file manager is Samsung's. So, I think your assumption that there is a universal file manager app across all Android devices is flawed. – CommonsWare Oct 23 '21 at 20:32
  • `I would like to be able to open the built-in Android file manager app to show my folder to the user.` Why not let the user choose wich app to use for just browsing? Like with ACTION_VIEW or ACTION_SEND? – blackapps Oct 24 '21 at 09:11
  • @blackapps, if the user could just choose from a list of file manager apps, I'd be fine with that. But on my personal device, I am also offered an audio book player and a PDF viewer as choices for opening a folder. I think users would find it confusing. – George Oct 24 '21 at 16:49
  • ???? But you said that you did knot know how to do it. So where and how did you get that list? – blackapps Oct 24 '21 at 16:53

0 Answers0