【问题标题】:Open App from URL works on Firefox for Android but not on Google Chrome从 URL 打开应用程序适用于 Firefox for Android,但不适用于 Google Chrome
【发布时间】:2015-06-14 15:33:59
【问题描述】:

我想在用户点击我的网页链接时打开我的 Android 应用程序(最好来自 Facebook 分享帖子,但让我们从纯 URL 开始)。

为此,我创建了一个活动UrlReceiver 并将此代码添加到我的AndroidManifest.xml 文件中(URL 仅用于测试目的):

<activity
        android:name=".main.core.UrlReceiver"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.VIEW"/>
            <category android:name="android.intent.category.DEFAULT"/>
            <category android:name="android.intent.category.BROWSABLE"/>

            <data
                android:host="martinfowler.com"
                android:pathPrefix="/"
                android:scheme="http"/>
            <data
                android:host="www.martinfowler.com"
                android:pathPrefix="/"
                android:scheme="http"/>
            <data
                android:host="test"
                android:scheme="myapp"/>
        </intent-filter>
</activity>

这在 Firefox for Android 上有效,当我输入 myapp://test/ 时,它会自动打开我的应用程序,当我输入 martinfowler.com 时,URL 旁边有一个 Android 头像,可以点击到我的应用程序。这很好。

但它不能Google Chrome 上运行。当我输入 myapp://test/ 时,它会启动 Google 搜索,当我输入 martinfowler.com 时,它只会打开网页。

我开始在网上对此进行挖掘,并找到了这个文档:https://developer.chrome.com/multidevice/android/intents,说明自定义模式在 Chrome 中不再适用,所以我尝试使用这个 URL(根据文档):

intent://test/#Intent;scheme=myapp;package=com.my.app;end
intent://#Intent;scheme=myapp;package=com.my.app;end
intent://test/#Intent;package=com.my.app;scheme=myapp;end
intent://#Intent;package=com.my.app;scheme=myapp;end

但这些也开始了 Google 搜索。我该怎么做才能从 Google Chrome 中的 URL 打开我的应用程序?

我已经在 KitKat 和 Lolipop 上对此进行了测试。

【问题讨论】:

    标签: android google-chrome firefox intentfilter


    【解决方案1】:

    问题是我一直在将 URL 输入(或复制)到 Chrome Omnibox(搜索栏)中,根据这个问题:https://code.google.com/p/chromium/issues/detail?id=451956 它不再是支持:

    http://crbug.com/331571 中,我们决定不启动 Intent,如果 原始导航是从用户输入开始的,因为我们认为 通常,用户在键入时不会期望离开 Chrome URL 进入多功能框。

    因此,在谷歌浏览器中从 URL 打开应用程序仅适用于链接点击,而在使用搜索栏时不起作用。

    【讨论】:

    • 谢谢。以上哪个链接最终是有效的?
    • 在谷歌浏览器中?无,您必须点击该链接,您不能在 Chrome 多功能框(搜索栏)中输入/复制它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-08
    • 2014-11-17
    • 2015-06-09
    • 2011-08-21
    相关资源
    最近更新 更多