android - 通过 Intent 启动浏览器,带有架构 "HTTP"(大写)错误的 url

标签 android android-intent

我使用代码启动一个 Intent :

startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));

为什么如果 url 以“http”开头是有效的,但如果 url 以“HTTP”(大写)开头,它会抛出 ActivityNotFoundException?这很奇怪,因为 url 遵循标准 RFC 2396。

最佳答案

您可以使用:normalizeScheme()

//Return an equivalent URI with a lowercase scheme component. 
// This aligns the Uri with Android best practices for intent filtering.
// For example, "HTTP://www.android.com" becomes "http://www.android.com" 
Uri uri =  Uri.parse(url).normalizeScheme()
startActivity(new Intent(Intent.ACTION_VIEW, uri))

在这里查看更多信息:normalizeScheme

关于android - 通过 Intent 启动浏览器,带有架构 "HTTP"(大写)错误的 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27251456/

相关文章:

android - 是否可以向用户隐藏特定应用程序?

java - 如何解决 android b.a.a.b 超时错误?

Android 浏览器渲染边界半径不正确,边界较大

android - 从后台打开应用程序时,应用程序启动器 Activity 重新打开

android - Retrofit 中的 Rxjava observeOn 和 subscribeOn

java - 如果从 MyApp 调用文件在其他应用程序中查看,文件不会显示其内容

android-intent - Kotlin 可打包类抛出 ClassNotFoundException

java - 是否可以使用 Integer.parseInt(String) 将我们通过 get string extra Intent 获得的字符串值转换为整数

android - 发送电子邮件时出现错误“没有应用程序可以执行此操作”

java - 旋转 以度为单位的 View 变换(仅在 x 轴上)