找不到处理CREATE_DOCUMENT意图的活动

6
我的崩溃报告工具报告了一个经常出现的错误,主要出现在安卓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)

这些设备不支持SAF有什么原因吗?我应该如何正确地解决这个问题?
2个回答

4

此帖子中所述,您需要设置

intent.setType("*/*");

在你的情况下,可能是

intent.setType("application/pdf")

等待故障消失。


您的解决方案应被标记为正确。 - acmpo6ou

3

首先,您可以做的是避免崩溃 -


       if (intent.resolveActivity(getPackageManager()) != null) {
                context.startActivity(intent);
            } else { 
    Toast.makeToast(context, "No application found on device to open view", Toast.LENGTH_SHORT).show() 
}

这个答案更好:https://dev59.com/PZXfa4cB1Zd3GeqPh6OG#57453337 - acmpo6ou

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接