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:
- 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.
- 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).
- 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.