Elio Khattar
Elio Khattar

Reputation: 330

No Activity found to handle intent OPEN_DOCUMENT_TREE on some Samsung Android devices

My android application opens the "document tree" selector to prompt read permission on an external storage full directory (as per android 10+ scoped storage rules).

Relative Code

    Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
    intent.addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
    startActivityForResult(intent, REQUEST_ID_PERMISSION);

Works fine for all tested versions and device variants. But, my crashlytics shows the below error ocuring a considerable number of times for some Samsung devices. (A20 - Android 9 | S10/10+ - Android 10 & 11 | Note20 - Android 11)

Fatal Exception: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.OPEN_DOCUMENT_TREE flg=0x40 }
   at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2071)
   at android.app.Instrumentation.execStartActivity(Instrumentation.java:1717)
   at android.app.Activity.startActivityForResult(Activity.java:5252)
   at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:676)

Any potential reason and solution for this problem, knowing that:

  1. I can check the availability of the activity prior to launching the OPEN_DOCUMENT_TREE, but this will result in the document selector not opening.
  2. Some old answers suggest adding intent.setType("*/*"), but this is no longer valid, and causes crashes with reasons explained in another questions (That i can no longer find, but is irrelevant here).
  3. I also think it might be very likely related to the fact that some users have disabled the FILES app on their devices, since MOST PROBABLY the error is not occurring on all the devices models listed above, but for a subset.

thank you.

Upvotes: 3

Views: 3620

Answers (3)

Jan
Jan

Reputation: 23

I just ran into this exact same issue on my rooted OnePlus 6 with OxygenOS version 10.3.6 (Android 10), and the error message I got is pretty much identical to yours:

Error: Failed to choose folder: No activity found to handle intent { act=android.intent.action.OPEN_DOCUMENT_TREE flg=0xc3 (has extras) }

How I Fixed It

To resolve the error I had to manually install the com.android.documentsui application, and I did so by following some of the steps detailed in this Android Stack Exchange answer: https://android.stackexchange.com/a/253276/404185

I had root on my phone, so happily I didn't have to bother with ADB. I simply opened a terminal emulator on my phone and executed the following two commands, one after the other:

su
cmd package install-existing com.android.documentsui
⚠️ Important: Remember to reboot your phone after executing either the ADB or terminal commands!

Addendum: Possible Code Workaround

I am not 100% sure this code is applicable, but perhaps this fallback code can be used to gracefully handle this exception without requiring any user interaction nor the installation of any applications: https://github.com/signalapp/Signal-Android/commit/6e3751a0c5870f8dc4ad9d210ce08b153c3307bf

Upvotes: 0

Ehtisham Ali Shah
Ehtisham Ali Shah

Reputation: 113

Following solutions can fix this issue:

  1. Make sure you are not accessing the restricted folders as described here.
  2. Make sure that the Files app is accessible. If its disabled then this error will show up.
  3. In case if Files app is disabled or someone rooted the phone and deleted the Files app, display an appropriate message and navigate the user to a Files app on play store.
  4. If the function is crucial for the app. Check for the app on the app startup and warn user that the feature wont work unless Files app is enabled or installed. (But its not a great UX).

Upvotes: 0

atrocia6
atrocia6

Reputation: 481

Data point: I came across this discussion while searching the web for an explanation of a similar exception / crash reported by a user of an app of mine (on a Samsung S10). I pointed the user to this discussion, and sure enough, he had deactivated the Files app, and reactivating it solved the problem.

Upvotes: 1

Related Questions