Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No Activity found to handle Intent CREATE_DOCUMENT

Tags:

android

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?

like image 866
guillaume-tgl Avatar asked Apr 01 '16 08:04

guillaume-tgl


2 Answers

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.

like image 100
Blitz Avatar answered Sep 19 '22 01:09

Blitz


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() 
}
like image 22
crashOveride Avatar answered Sep 20 '22 01:09

crashOveride