The Android Intent system is a flexible mechanism to enable apps to handle content and requests. Multiple apps may declare matching URI patterns in their intent filters. When a user clicks on a web link that does not have a default launch handler, the platform may show a dialog for the user to select from a list of apps that have declared matching intent filters.
The Android M Developer Preview introduces support for App Links, which improves upon existing link handling by allowing app developers to associate an app with a web domain they own. When developers create this association, the platform can automatically determine the default app used to handle a particular web link and skip asking users.
Declare a Website Association
Website owners must declare associations with apps to establish an app link. The site owner
declares the relationship to an app by hosting a JSON file, named statements.json
, at the
well-known location on the domain:
http://<domain>:<optional port>/.well-known/statements.json
Note: During the M Developer Preview period, the JSON file is verified via http protocol. For the official release of the platform, the file is verified over encrypted, https protocol.
This JSON file indicates the Android app that should be used as the default handler for the URLs under this domain. It identifies the app based on these fields:
package_name
: The package name declared in the app's manifest.sha256_cert_fingerprints
: The SHA256 fingerprint of your app’s signing certificate. You can use the Java keytool to generate the fingerprint using the following command:keytool -list -v -keystore my-release-key.keystore
The following file listing shows an example of the contents and format of a
statements.json
file:
[{ "relation": ["delegate_permission/common.handle_all_urls"], "target": { "namespace": "android_app", "package_name": "<package name>", "sha256_cert_fingerprints": ["6C:EC:C5:0E:34:AE....EB:0C:9B"] } }]
Request App Link Verification
An app can request that the platform automatically verify any app links defined by the host names
in the data elements of its intent filters against the statements.json
files hosted on
the respective web domains. To request app link verification, add an android:autoVerify
attribute to each desired intent filter in the manifest, as shown in the following manifest code
snippet:
<activity ...> <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="www.android.com" /> <data android:scheme="https" android:host="www.android.com" /> </intent-filter> </activity>
When the android:autoVerify
attribute is present in an app manifest, the platform
attempts to verify app links when the app is installed. If the platform cannot successfully
verify the app links, the app is not set as the preferred app to handle the web links. The next
time a user opens one of the links, the platform falls back to presenting the user with a
dialog.
Note: In testing, there is a potential for a false positive if verfication fails, but the user has explicitly enabled the app to open supported links without asking, using the system Settings app. In this case, no dialog is shown and the link goes directly to your app, but only because of the user setting, and not because verification succeeded.
Managing App Link Settings
Users can change app link settings so URLs are handled the way they prefer. You can review and manage app links in the system Settings app, under Settings > Apps > App Info > Open by default.