【问题标题】:Android Deep linkingAndroid 深度链接
【发布时间】:2016-01-26 10:38:40
【问题描述】:

我正在尝试在 Android 上添加深层链接,因此在我的网页中我替换了这样的 iframe

<iframe  scrolling="no" width="1" height="1" style="display: none;" 
src="myscheme://post/5002"></iframe>

在我的 manifest.xml (android app) 中

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme">
    <activity
        android:name=".MyActivity"
        android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

        <intent-filter>
            <action android:name="android.intent.action.VIEW"></action>

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

            <data android:scheme="myscheme" />
        </intent-filter>
    </activity>
</application>

但是当我在 chrome 中打开网页时,它没有显示“打开方式”对话框来选择我的应用

我使用这个测试了 android 的深度链接并出现了对话框

adb shell am start -W -a android.intent.action.VIEW  -d "myscheme://whatever" 

【问题讨论】:

  • 您测试的是哪个版本的 Android?

标签: android html web deep-linking


【解决方案1】:

Android 版 Chrome 25 及更高版本中的功能略有变化。不再可以通过设置 iframe 的 src 属性来启动 Android 应用程序。你应该改用“intent:”语法

intent://host/#Intent;scheme=protocol;package=com.domain.apppackage;end

基于意图的 URI 的基本语法如下:

意图: HOST/URI-path // 可选主机
#意图;
包=[字符串];
动作=[字符串];
类别=[字符串];
组件=[字符串];
方案=[字符串];
结尾;

请查看page

【讨论】:

    【解决方案2】:

    iframe 解决方案不再适用于最新版本的 Chrome。正如 Anas 所说,您需要创建一个带有“intent://..:”地址的链接。用户还需要执行一些操作才能打开链接。

    为了解决这个问题,我创建了一个链接缩短工具。你可以在这里使用它: http://www.uppurl.com/

    此工具负责根据用户浏览器创建适当的深层链接。我建议您使用它,因为它为您解决了很多工作,您甚至不需要修改或拥有服务器。

    【讨论】:

      【解决方案3】:

      不确定,但您可以尝试使用 JavaScript 代替 iframe:

      location.href = "myscheme://post/5002"
      

      另外,为了测试它是否正常工作,您可以尝试在 Intent-filter 中设置数据元素的主机和路径:

      <data android:scheme="myscheme"
                        android:host="post"
                        android:pathPrefix="502">
      

      【讨论】: