我正在运行 context.startActivity(intent);
,我的 Intent 如下所示:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setDataAndType(Uri.parse(uri), mimeType);
此时的 uri 是一个字符串 http://remote.server.path/photo-12212324324.jpg
mimeType 是 image/jpeg
这是一个异常示例。
12-07 20:48:55.934: I/ActivityManager(633): START u0 {act=android.intent.action.VIEW dat=http: typ=image/jpeg flg=0x1} from pid 1414
12-07 20:48:55.964: W/dalvikvm(1414): threadid=1: thread exiting with uncaught exception (group=0x40cb5ba0)
12-07 20:48:56.034: E/AndroidRuntime(1414): FATAL EXCEPTION: main
12-07 20:48:56.034: E/AndroidRuntime(1414): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=http: typ=image/jpeg flg=0x1 }
12-07 20:48:56.034: E/AndroidRuntime(1414): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1760)
12-07 20:48:56.034: E/AndroidRuntime(1414): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1555)
12-07 20:48:56.034: E/AndroidRuntime(1414): at android.app.Activity.startActivityForResult(Activity.java:3431)
现场至少有两台设备会发生这种情况,其中一台是 Samsung Galaxy S5,因此,我怀疑没有应用程序来处理该 Intent ,因为用户至少会安装 Samsung Gallery 应用程序。我知道我可以处理异常并显示错误,但这并不是真正的解决方法。
最佳答案
I am running context.startActivity(intent); and my intent looks like this:
嗯,FLAG_GRANT_READ_URI_PERMISSION
在这里没用。这仅适用于当您的 Uri
来自 ContentProvider
时。
I doubt that there's no app to handle the intent as the user will have at least Samsung Gallery app installed
设备 可能有那个应用程序。 用户可能不会。请记住,在 Android 4.2+ 平板电脑和 Android 5.0+ 手机上,一台设备可能有多个用户。其中一些用户可能是“受限帐户”,他们只能访问一组列入白名单的应用。
请不要假设所有用户都可以访问可以下载和查看图像的应用。
此外,我不认为无论“Samsung Gallery 应用程序”是什么,都一定会支持 http
作为方案。
I know I can just handle the exception and show an error, but that's not really a fix
如果您不想显示错误,请实现您自己的图像查看器作为备用。
关于android - 启动 android.intent.action.VIEW 时出现 ActivityNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34156110/