Android URI方案与应用链接 [英] Android URI schemes vs App Links

查看:124
本文介绍了Android URI方案与应用链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android应用链接仅适用于Android 6.0,与Android 4.2中的深层链接不同,但行为和编码有何不同?

Android App Links works only from Android 6.0, unlike Deep Links from Android 4.2 but what the difference in behavior and coding?

我阅读了文档但没有看到

I read the documentation but did not see the difference.

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

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

推荐答案

URI方案深层链接(Android 4.2)



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

URI Scheme Deep Linking (Android 4.2)

The standard URI scheme deep linking (Android 4.2) allowed developers to register an app for URI scheme i.e. pinterest:// and when a user clicked this link and had the app installed, the app would open. If the app was not installed, it would produce a 'Page Not Found' error.

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

It works by registering an app to respond to a given URI via the intent filter in the manifest.

<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>

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

You would then handle the link by grabbing the intent string from the given activity.

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商店,或(可选)为您提供后备网址

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

App Links were introduced to replicate the functionality of iOS Universal Links. App Links are a simple way to turn website links into App Links. Therefore, if a normal HTTP/HTTPS link is clicked and the corresponding app is installed, it will open immediately. If the app is not installed, a fallback web link is provided.


  • 您必须具有正常运行的网站

  • 用户必须使用Android 6.0

在应用链接的情况下,清单看上去会略有不同。

In the case of App Links your manifest is going to look slightly different.

<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.com

You then must register your website to handle App Links. You need to create an assetlinks.json file and host it on your website at yoursite.com/.well-known/assetlinks.com

/。well-已知/assetlinks.com

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



延迟的深层链接



不幸的是,这两种方法都不支持延迟的深层链接,这是对内容进行深层链接的能力尚未安装应用程序时在应用程序内部安装。这对于新用户来说是一次重要的用户体验,因此我建议使用第三方分支 (适用于分支)或Firebase。他们将处理所有功能和特殊情况,并包括其他功能,例如深视图和应用横幅,如果您对此感兴趣的话。

Deferred Deep Linking

Unfortunately, neither of these methods support deferred deep linking, which is the ability to deep link to content inside the app when the app has not been installed yet. This is an important user experience for on-boarding new users so I suggested using a third-party like Branch (full disclosure I work for Branch) or Firebase. They will handle all of the functionality and edge cases, as well as, include other functionality like deep views and app banners if that's something you're interested in.

这篇关于Android URI方案与应用链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆