Android M - 应用程序链接在 Chrome 中不起作用

标签 android google-chrome deep-linking android-6.0-marshmallow

因此,我希望在一些新应用程序中实现应用程序链接,并且我已经通读了开发说明、设置服务器、添加具有正确 json header 的文件并构建了一个测试应用程序。如果我给自己发送一封附有链接的电子邮件,Android M 中引入的应用深度链接似乎可以正常工作,但是当我在 chrome 的示例页面上执行此操作时,它只会重新加载页面。我只是在访问我的网络服务器上的根页面。 (https://www.EXAMPLE.com)。我最初在平板电脑上使用 chrome 时遇到了一些证书问题,但我添加了根证书,现在它变成了绿色

我使用的是 Nexus 7 2013,刚删除并运行 Android M 和 Chrome,已更新。

我在我的服务器上提供一个 HTML 文件(就像我有一个后备页面一样)。

不知道这是我使用网页的方式/回退,还是我配置有误。它在 Gmail 中运行良好,没有任务选择器,但在 Chrome 中却不行。

我尝试混合一些示例 html 看起来像这样,但没有一个有效。

<a href="EXAMPLE://">Click HERE for schema</a>

<a href="https://www.EXAMPLE.com/">Click HERE for url with slash</a>

<a href="https://www.EXAMPLE.com">Click HERE for url, no slash</a>

<a href="#" onclick="window.location('https://www.EXAMPLE.com/')">Trying with onclick javascript</a>

我的安卓 list :

<activity
        android:name=".deepActivity"
        android:label="@string/title_activity_deep" >
        <intent-filter android:autoVerify="true">

            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

            <data android:scheme="http" android:host="www.EXAMPLE.com" />
            <data android:scheme="https" android:host="www.MYDOMAIN.com" />

            <!-- note that the leading "/" is required for pathPrefix-->
            <!-- Accepts URIs that begin with "example://gizmos”-->

        </intent-filter>

https://developer.android.com/training/app-links/index.html

编辑:

我一直在使用以下命令测试自动验证:

adb shell dumpsys package d | grep DOMAIN -ab5

我得到了结果:

230:  Package: com.DOMAIN.deeplinkingtest
275:  Domains: www.DOMAIN.com
308-  Status:  undefined

来自文档

Shows the current link-handling setting for this app. An app that has passed verification, and whose manifest contains android:autoVerify="true", shows a status of always. The hexadecimal number after this status is related to the Android system's record of the user’s app linkage preferences. This value does not indicate whether verification succeeded.

最佳答案

...but when I do it on a sample page in chrome, it just reloads the page

我假设您的意思是您只是进入 Chrome 并输入 https://example.com在浏览器栏中。

不幸的是,如果您在浏览器栏中键入 URL,应用链接将不起作用。这听起来可能令人沮丧,但有充分的理由证明它不起作用。正如 Google Dev Advocate Paul Kinlan 所解释的那样,这将是一种糟糕的用户体验:

If a user enters a URL into the address bar of the system, then the intention of the user is to visit the page in question. We don’t believe that the user intended to go to the app. Ergo, redirecting the user to the app is a poor user experience.

link

此答案仅与在 Chrome 网址栏中输入网址有关。但是,如果用户点击网页中的链接,情况也是如此(大部分情况下)。让我们来解决为什么事情不适用于您的每个示例链接。我将从中间的两个开始:

<a href="https://www.EXAMPLE.com/">Click HERE for url with slash</a>

<a href="https://www.EXAMPLE.com">Click HERE for url, no slash</a>

为了让这些链接启动您的应用程序,Chrome 必须使用 action.VIEW 向系统发送一个 Intent 。 , category.DEFAULT **, category.BROWSABLE , 和方案 httphttps .您可以创建一个 Intent 过滤器来捕获此 Intent (您的 App Linking Intent 过滤器将起作用):

<intent-filter android:autoVerify="true">
    <action android:name="android.intent.action.VIEW"/>
    <category android:name="android.intent.category.DEFAULT"/>
    <category android:name="android.intent.category.BROWSABLE"/>
    <data android:scheme="http"/>
    <data android:scheme="https"/>
    <data android:host="www.example.com"/>
</intent-filter>

如果您检查日志(或者只是测试它),您会发现 Chrome 没有触发 intent。他们选择内部处理该链接(通过导航到新页面)。这是 Chrome 而非 Android 的功能。没有办法改变这一点。但是,您可以在 URL 中指定 Chrome 将遵循的自定义方案。这将我带到您的第一个 URL:

<a href="EXAMPLE://">Click HERE for schema</a>

Chrome 将尊重此 URL 中的方案并触发一个 Intent :action.VIEW , category.DEFAULT **, category.BROWSABLE , 和方案 EXAMPLE .根据您设置 Intent 过滤器的方式,这将启动您的应用程序。您的第一个冲动可能是添加 EXAMPLE计划到您的 App Linking Intent 过滤器:

<intent-filter android:autoVerify="true">
    <action android:name="android.intent.action.VIEW"/>
    <category android:name="android.intent.category.DEFAULT"/>
    <category android:name="android.intent.category.BROWSABLE"/>
    <data android:scheme="http"/>
    <data android:scheme="https"/>
    <data android:scheme="EXAMPLE"/>
    <data android:host="www.example.com"/>
</intent-filter>

这将允许您点击 Chrome 中的链接并让 Chrome 打开您的应用程序。但是它现在会破坏应用程序链接。专业的解决方案是保持您的 App Linking Intent 过滤器不变,并添加第二个 Intent 过滤器来捕获您的自定义方案:

<!-- EXAMPLE scheme intent filter -->
<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:scheme="EXAMPLE"/>
    <data android:host="www.example.com"/>
</intent-filter>

<!-- App Linking intent filter -->
<intent-filter android:autoVerify="true">
    <action android:name="android.intent.action.VIEW"/>
    <category android:name="android.intent.category.DEFAULT"/>
    <category android:name="android.intent.category.BROWSABLE"/>
    <data android:scheme="http"/>
    <data android:scheme="https"/>
    <data android:host="www.example.com"/>
</intent-filter>

这可能是 TMI,但触及根源有助于理解为什么一切正常/不正常。

** 记住系统会加上category.DEFAULT任何隐含的 Intent 。

============================================

更新: 我应该补充一点,使用你自己的方案是不好的做法。记录了一个完全更好的方法 here

关于Android M - 应用程序链接在 Chrome 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33817827/

相关文章:

Android FCM通知分组

android - 带有 api 16 和 Webview 的 MotionEvent (Android)

html - chrome 上的颜色选择器给出了错误的值

javascript - 我可以以某种方式将当前运行的 javascript 函数记录到 Chrome 开发者控制台中吗?

android - Android 终端的 URL Scheme/Deeplink 测试

java - jQuery 地址 - 表单提交后重定向

android - 使用 gps 获取一个人走过的距离

java - 如何将 EditText 默认为整数但允许小数输入?

html - Chrome 对齐元素 : baseline for select and input elements

ios - 通过像 HockeyApp 这样的第 3 方 App Store 延迟深度链接?