在浏览器中输入时 Android 自定义 URI 方案编码不正确
我正在编写我的 android 应用程序,我想定义一个自定义 URI 方案,以便用户可以通过在浏览器中键入 URI 来访问我的应用程序,例如: myapps://cate=1&id=3
我成功地在我的应用程序,但我发现对于某些设备,浏览器以不同的方式处理链接。
在我的 HTC Flyer 中,它可以正确打开我的应用程序,但在 Samsung Galaxy Ace 中,浏览器将链接转换为 myapps%3A%2F%2Fcate=1%26id=3,该链接经过编码,只需在 google 上搜索“myapps:/ /cate=1&id=3" 对我来说,而不是打开应用程序。
我在清单中定义意图过滤器,如下所示:
<intent-filter >
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="myapps"/>
</intent-filter>
对这个问题有帮助吗?谢谢
编辑
我刚刚查看了android浏览器的源代码,它定义了它接受的方案:
protected static final Pattern ACCEPTED_URI_SCHEMA = Pattern.compile(
"(?i)" + // switch on case insensitive matching
"(" + // begin group for schema
"(?:http|https|file):\\/\\/" +
"|(?:inline|data|about|content|javascript):" +
")" +
"(.*)" );
现在我明白为什么自定义方案不起作用了! 任何应用程序都应该只捕获方案:http、https、file、inline、data、about、content、javascript。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么它必须是自定义 uri?
我会尝试使用标准 URL,然后为其定义一个广播接收器。
http://youtube.com 或 http://maps.google.com 可以工作。只需尝试在 Galaxy Ace 的 Android 浏览器中输入这两个 URL。
Why does it have to be a custom uri?
I'd try it with a standard URL and then I'd define a broadcast receiver for it.
That's essentially how http://youtube.com or http://maps.google.com work I think. Just try typing those two URLs in your Android browser of your Galaxy Ace.