Goal: Help Android developers with a quick and straightforward Android App Links implementation example
If you’re already familiar with the technical details behind the design, configuration, implementation, and verification of Android App Links, and you would like to get started in your own app right away, then this blog post is for you. If you are interested in learning more about those details, we have a codelab that covers them.
Here is what you will need to successfully implement an Android App Link:
- Latest version of Android Studio
- A deployed domain with public access
- (Optional) Google Play developer account setup
Here are the steps to support an Android App Link. These steps create a basic application that displays the Intent information from an App Link.
Step 1: Create an Empty Compose Activity
1.1 In Android Studio create a new project and select “Empty Compose Activity”.
1.2 Make sure the application runs as expected before you start adding code. You should see an empty application with a “Hello Android!” message:
Step 2: Update Manifest
2.1 Include the intent filter in AndroidManifest.xml so the MainActivity will open Android App Links.
2.2 Make sure to update domain example.com and path: /example-path. These should reflect your website implementation structure.
Step 3: Update Android App Link logic
3.1 In order to parse the Android App Link data received you have to add the following logic into the main activity (MainActivity.kt) of your app:
3.2 If you run this logic you will see the following text strings: One displays the Hello Android! message, the second displays the action for the intent that was called, and the third one displays the URL for the intent that was called.
Step 4: Obtain the certificate fingerprint
Before uploading the assetlinks.json file, which is part of the Digital Asset Links (DAL) protocol, you need to get the application certificate fingerprint. In this case since we haven’t released the app to the Google Play Store we can use the debug certificate fingerprint. If you want to upload the app to Google Play, you must include your releasing signing key. This page explains how to do it.
4.1 To obtain the debug/release certificate fingerprint, run the following command under the “Run Anything” menu in Android Studio:
Important Note: The debug certificate fingerprint is insecure by nature and should only be used for debugging purposes. The Google Play Store will reject any app downloaded with this certificate.
4.2 From the output of this command, copy the fingerprint under the SHA-256: section:
Step 5: Upload assetlinks.json file
We have a separate blog post detailing this process. Here we present the short version.
5.1 Under your domain in the following location: <example.com>/.well-known/ include a file called assetlinks.json with the following format:
The resulting link should look something like this:
You should also make sure the file is publicly accessible.
5.2 Update the package_name and sha256_cert_fingerprints with your own package name and fingerprint that you obtained in the previous step.
Step 6: Verify Android App Link
You should now be ready to launch your app, launch an intent, and verify that your app receives it as an Android App Link.
6.1 Run your app and make sure you see the main activity appear.
6.2 Run the following adb command:
6.3 Verify that the Android App Link data is received on the main activity screen.
Step 7: Troubleshoot (Optional)
If you don’t see the Android App Link data received, you might have to reinitialize the Android App Link verification process. Here are commands to achieve this:
7.1 Reset Android App Links state.
7.2 Run the verification process. It might take up to 5 minutes before the verification services get the updates.
7.3 Obtain the verification results.
This command outputs the result of the verification process, and you should see output similar to this:
Make sure the status of your domain is verified. If not, please start the verification process again.
Congratulations! You successfully implemented your first Android App Link. If you are interested in a deeper look at this process, please refer to this codelab.
Android App Links implementation in a few steps! was originally published in Android Developers on Medium, where people are continuing the conversation by highlighting and responding to this story.
Leave a Reply