Android URI schemes vs App Links

左心房为你撑大大i 提交于 2019-11-30 03:21:39

问题


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.

Deep Links: https://developer.android.com/training/app-indexing/deep-linking.html

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


回答1:


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.

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);
}

NOTE: If the user was coming from Chrome you would need to include separate handling. Chrome will not throw an error if the app is not installed, it will take you to the Play Store or (Optionally) provide you with a fallback URL

App Links (Android 6.0)

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.

Requirements

  • you must have a functional website
  • the user must be on Android 6.0

Configuration

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>

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-known/assetlinks.com

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

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.



来源:https://stackoverflow.com/questions/45169243/android-uri-schemes-vs-app-links

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!