Android URI 方案与应用链接

标签 android deep-linking applinks

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

最佳答案

URI Scheme 深度链接 (Android 4.2)

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

它的工作原理是注册一个应用程序以通过 list 中的 Intent 过滤器响应给定的 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>

然后您将通过从给定 Activity 中获取 Intent 字符串来处理链接。

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

配置

对于 App Links,您的 list 看起来会略有不同。

<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。他们将处理所有功能和边缘情况,并包括其他功能,如深度 View 和应用横幅,如果您对此感兴趣的话。

关于Android URI 方案与应用链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45169243/

相关文章:

android - 我们可以在 Android 应用程序中使用 UIAutomator 吗?

android - 在android中创建并写入一个xml文件

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

ios - 如何在 IOS 中使用 Facebook URL Schemes

java - 硬件支持 HAL 太慢,只能写入 720 帧中的 0

java - Android "application stopped unexpectedly"- google Hello MapView 教程

android - 是否可以将一个 facebook 应用程序深度链接到两个 android 应用程序?

javascript - jQuery 地址更改事件

android - 使用 Facebook 的移动托管 API 安装 android 应用程序,但无法获取查询数据?

android-studio - 如何使测试应用程序链接起作用