在浏览器中输入时 Android 自定义 URI 方案编码不正确

发布于 2024-12-20 18:34:29 字数 1147 浏览 2 评论 0 原文

我正在编写我的 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。

I am writing my android application, which I want to define a custom URI scheme, so that user can go to my app by typing a URI in browser, like: myapps://cate=1&id=3

I successfully implemented this in my apps, but I discover that for some device, the browser treat the link differently.

In my HTC Flyer, it opens my app correctly, but in Samsung Galaxy Ace, the browser translates the link to myapps%3A%2F%2Fcate=1%26id=3, which is encoded, and it just google the "myapps://cate=1&id=3" for me instead of open the app.

I define the intent filter in the manifest like this:

<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>

Any help on this issue? thanks

EDITED

I just looked at the source code of android browser, it defined what scheme it accepts:

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):" +
    ")" +
    "(.*)" );

Now I understand why custom scheme won't work!
Any apps should only capture schemes: http,https,file,inline,data,about,content,javascript.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情仇皆在手 2024-12-27 18:34:29

为什么它必须是自定义 uri?

我会尝试使用标准 URL,然后为其定义一个广播接收器。

http://youtube.comhttp://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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文