在Chrome 86.0.4240.75上启动“打开URL”意图时,ActivityNotFoundException崩溃

时间:2020-10-09 13:07:51

标签: android android-webview android-chrome

Chrome for Android version 86.0.4240.75仅在几天前发布。在使用该版本的Chrome / Android System WebView的设备上,首次推广还没有开始,但是我们看到了一个新的崩溃,其数量正在直线上升。

val intent = Intent(Intent.ACTION_VIEW)
intent.setDataAndType(Uri.parse(url), "text/html")
intent.addCategory(Intent.CATEGORY_BROWSABLE)
startActivity(intent)

对于任何URL ,在使用版本86.0.4240.75的任何设备上,上述代码都会崩溃,并带有ActivityNotFoundException:

android.content.ActivityNotFoundException: No Activity found to handle Intent 
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1854) 
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1544)

好像是Chrome中的错误,但有人能找到解决方法吗?

1 个答案:

答案 0 :(得分:1)

有点意外,但是我发现了一个简单的解决方法。实际上是两个:删除 MIME类型或删除类别

即使在86.0.4240.75下也可以正常工作:

val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
intent.addCategory(Intent.CATEGORY_BROWSABLE)
startActivity(intent)

这也是:

val intent = Intent(Intent.ACTION_VIEW)
intent.setDataAndType(Uri.parse(url), "text/html")
startActivity(intent)

(我不确定首先定义text/htmlCATEGORY_BROWSABLE有什么好处,因为似乎都不是强制性的。)

相关问题