ZOFTINO.COM

Android App Links

When user clicks a link in an android app or app fires web URI intent in response to some events in app, android system matches the intent to the target app using app links. App links, introduced in android 6.0 and API level 23, allows apps to configure links that they can handle so that system automatically matches links to apps for handling the link requests.

With app links, apps tell android system which links they can handle and for which links they want to be default handler. Your app can be designated as default app for links by defining app links in the manifest file in your app and enabling auto verification of association.

And also, android system provides a way for users to override app links configuration provided by apps using android settings. Meaning user settings override app configuration when android system decides which app to use to open a link.

App Links Setup

The main purpose of app links in android is to provide a mechanism for handling web URI intents automatically. Web URI intent represents a link to website or page. To make app links work, you need to configure your app and website.

Configuration for association between app and website needs to be done both in app and on website. Both app and website developers need to work together to define association between an app and website.

Website’s association or relationship with other digital assets can be defined using asset link protocol. The file which contains digital asset relationship, called digital asset links file, needs to be published on websites. Digital asset links file name and path needs to be as per naming conventions.

App side configuration for handling links needs to be added to manifest file. Intent filter is used to define urls that app can handle. Android system downloads digital assets link file from the websites and verifies app links defined in manifest if you want to make your app as default handler for the defined links by setting auto verify to true.

Continue reading for information on how to create these configurations.

Android System App Links Handling

When user clicks a link or program fires web URI intent, android system takes action depending on the user settings and installed app’s support for links.

If there is no default app for a link, system presents list of apps, which support the link, for user to select like below.

android select app for link

In order for your app to appear in the system presented list of apps which can handle a particular link, you need to add intent filter to your manifest. For example, below entry in manifest file and resultant screen shot on clicking the supported link.

<intent-filter>
        <action android:name="android.intent.action.VIEW"></action>
        <category android:name="android.intent.category.DEFAULT"></category>
        <category android:name="android.intent.category.BROWSABLE"></category>
        <data android:scheme="http"></data>
        <data android:scheme="https"></data>
        <data android:host="www.zoftino.com"></data>
    </intent-filter>
app in android select app for link

If there is only one app which supports the link, system directly forwards the request to the app.

User’s app links setting is given first preference. Meaning, if user chooses an app for a link, the link request (web URI intent) will be forwarded to the app for handling automatically.

User can set default app for links either by choosing open always option when app is selected from the system presented list of openable apps, see always option in the above screen shot or by going to settings > apps > gear icon > opening links > select an app > choose open in this app option for open supported links, screen shot below.

open by default in this app setting android app links

In both cases, apps which support app links are considered by the system. Meaning, the apps, which are listed in openable apps for a link, supports app links meaning the target link is added to intent filters in manifest file of the app. In the opening links settings also, for the selected app, the system gets supported links from manifest of the app. Here the only setting that user make is to indicate whether system opens the link with app by default or prompt the user every time.

Digital Asset Links

Digital asset links protocol allows you to define digital assets relationship. For example, it allows you to associate website with app.

Digital assets relationship following digital asset links protocol needs to be defined in asset links JSON file. This file needs to be published on website and it is served with content-type application/json. File should be named as assetlinks.json and file location should be like below path.

https://domain[:optional_port]/.well-known

To create a relationship between website and android app create statement in assetlinks.json like below.

[{
  "relation": ["delegate_permission/common.handle_all_urls"],
  "target": {
    "namespace": "android_app",
    "package_name": "com.zoftino",
    "sha256_cert_fingerprints":
    ["27:DE:D1:46:57:77:AE:21:59:35:76:2F:82:6C:63:7C:89:2F:DA:F3:48:27:CC:65:61:09:A7:B6:03:76:CD:36"]
  }
}]

You need to just replace package_name value with your app package name and sha256_cert_fingerprints value with SHA256 hash of your app certificate which is used to sign APK.

You can create SHA256 hash of your certificate by using the below command.

keytool -list -v -keystore %USERPROFILE%\.android\debug.keystore

Create Inent Handler for URIs

Android supports app links using intent filter. To enable your app to handle links, you need to define intent filter in manifest file.

<activity android:name=".VolleyActivity">
    <intent-filter>
        <action android:name="android.intent.action.VIEW"></action>
        <category android:name="android.intent.category.DEFAULT"></category>
        <category android:name="android.intent.category.BROWSABLE"></category>
        <data android:scheme="http"></data>
        <data android:scheme="https"></data>
        <data android:host="www.zoftino.com"></data>
    </intent-filter>
</activity>

But to make an app as default handler for a link, auto verify needs to be enabled in the app. To enable association verification, you need to set intent-filter’s android:autoVerify attribute to true.