Android app links is deep linking to allow a user directly open the content from a website links. Android use verified statements hosted on website to achieve the same.
Write detailed content for this section
Steps to Implement
-
Enable deep links to the application
-
Generate and Host Applinks JSON file to website
Implementation Guide
Add Intent filters
-
Add Intent filters to your app manifest that specify your website domain or URLs.
-
Add the autoVerify="true"attribute to the Intent filter elements. This signals to the system that it should attempt to verify the scheme and host domain(s) against your website's assetlinks.json configuration.
-
Declare website associations.
Code Example
<activity
android:name=".MainActivity"
android:exported="true"
...>
<!-- Make sure you explicitly set android:autoVerify to "true". -->
<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" />
<!-- If a user clicks on a link that uses the "http" scheme, your
app should be able to delegate that traffic to "https". -->
<!-- Do not include other schemes, as this will prevent verification. -->
<data android:scheme="http" />
<data android:scheme="https" />
<!-- Include one or more domains that should be verified. -->
<data android:host="www.example.com" />
<data android:host="*.example.com" />
</intent-filter>
</activity>
Configure website associations and applinks.json
To configure App Links, you must have to create a assetlinks.json and host it to a well-known location on your website. This file publicly declares which apps are authorized to handle links for your domain, and Android devices will retrieve this file from your server to verify your deep links.
- package_name: The package name declared of the app's build.gradle file.
- sha256_cert_fingerprints: The SHA256 of app's signing certificate. You can use the below command to generate the fingerprint using the Java keytool: keytool -list -v -keystore my-release-key.keystore
Verify App Links
After hosting the valid JSON file, install the app on your device. You can with the below command whether the system verified your app and set the correct link handling policies:
adb shell am start -a android.intent.action.VIEW \
-c android.intent.category.BROWSABLE \
-d "https://domain.name"
Troubleshoot
App link opens in the browser instead of the app
-
Check assetlinks.json: Check the file is valid JSON, and hosted at https://<your-domain>/.well-known/assetlinks.json, and hosted on Https
-
Check if sha256_cert_fingerprints in assetlinks.json exactly matches the signing key.
-
Check if the <intent-filter> in your AndroidManifest.xml includes android:autoVerify="true".
-
Run the ADB commands in the guide to get a fresh verification result.