My crash reporting tool reports a frequent error, mostly on Xiaomi devices on Android 5.0.2:
Fatal Exception: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.CREATE_DOCUMENT cat=[android.intent.category.OPENABLE] typ=application/pdf (has extras) }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1765)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1602)
at android.app.Activity.startActivityFromFragment(Activity.java:4391)
at android.app.Fragment.startActivityForResult(Fragment.java:1100)
at android.app.Fragment.startActivityForResult(Fragment.java:1084)
Is there any reason why these devices would not support SAF? And how could I work around this in a proper way?
As mentioned in this post you need to set
intent.setType("*/*");
or in your case probably
intent.setType("application/pdf")
for the crash to go away.
First thing you can do is to avoid the crash -
if (intent.resolveActivity(getPackageManager()) != null) {
context.startActivity(intent);
} else {
Toast.makeToast(context, "No application found on device to open view", Toast.LENGTH_SHORT).show()
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With