【问题标题】:Android URI schemes vs App LinksAndroid URI 方案与应用链接
【发布时间】:2017-12-23 11:12:27
【问题描述】:

Android App Links 仅适用于 Android 6.0,与 Android 4.2 中的 Deep Links 不同,但在行为和编码方面有何不同?

我阅读了文档,但没有发现差异。

深层链接:https://developer.android.com/training/app-indexing/deep-linking.html

应用链接:https://developer.android.com/training/app-links/index.html

【问题讨论】:

标签: android deep-linking applinks


【解决方案1】:

URI 方案深度链接 (Android 4.2)

标准 URI 方案深度链接 (Android 4.2) 允许开发人员为 URI 方案注册应用程序,即 pinterest://,当用户单击此链接并安装应用程序时,应用程序将打开。如果未安装该应用程序,则会产生“未找到页面”错误。

它通过注册应用程序以通过清单中的意图过滤器响应给定的 URI 来工作。

<intent-filter>
    <data android:scheme="your_uri_scheme" />
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
</intent-filter>

然后,您将通过从给定活动中获取意图字符串来处理链接。

Uri data = this.getIntent().getData();
if (data != null && data.isHierarchical()) {
    String uri = this.getIntent().getDataString();
    Log.i("MyApp", "Deep link clicked " + uri);
}

注意:如果用户来自 Chrome,则需要单独处理。如果未安装应用程序,Chrome 不会抛出错误,它会将您带到 Play 商店或(可选)为您提供后备 URL

应用链接(Android 6.0)

引入了应用链接以复制 iOS 通用链接的功能。应用链接是将网站链接转换为应用链接的简单方法。因此,如果点击正常的 HTTP/HTTPS 链接并安装了相应的应用程序,它将立即打开。如果未安装应用程序,则会提供后备 Web 链接。

要求

  • 您必须拥有一个功能正常的网站
  • 用户必须使用 Android 6.0

配置

对于应用链接,您的清单看起来会略有不同。

<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="yoursite.com" />
    <data android:scheme="https" android:host="yoursite.com" />
</intent-filter>

然后,您必须注册您的网站以处理应用链接。您需要创建一个assetlinks.json 文件并将其托管在您的网站yoursite.com/.well-known/assetlinks.json

/.well-known/assetlinks.json

[{
    "relation": ["delegate_permission/common.handle_all_urls"],
    "target": {
         "namespace": "android_app",
         "package_name": "io.branch.branchster",
         "sha256_cert_fingerprints": 
        ["14:6D:E9:..."]
    }
}]

延迟深层链接

不幸的是,这些方法都不支持延迟深度链接,即在尚未安装应用程序时深度链接到应用程序内部内容的能力。对于新用户来说,这是一个重要的用户体验,所以我建议使用像 Branch(我为 Branch 工作的完整披露)或 Firebase 这样的第三方。他们将处理所有功能和边缘情况,以及包含其他功能,如深度视图和应用横幅(如果您对此感兴趣)。

【讨论】:

  • 谢谢!为什么需要data != null &amp;&amp; data.isHierarchical()?是否有isHierarchical() == false 在 Deep Links 中的情况?
猜你喜欢
  • 1970-01-01
  • 2016-03-22
  • 2019-09-27
  • 1970-01-01
  • 2021-04-30
  • 1970-01-01
  • 1970-01-01
  • 2019-10-15
  • 2016-06-02
相关资源
最近更新 更多