Skip to main content

Handling App Links in Android

App Links allow your app to open specific content based on URL links, seamlessly connecting the web with your mobile app.

For more detailed exploration, please refer to the official Android documentation App Links: Handling Android App Links

  • Step 1 - Add Intent Filters in AndroidManifest.xml

    To declare your app's ability to open specific URLs, add an intent filter to the relevant activity in your AndroidManifest.xml.

    Here’s an example of an intent filter that handles URLs for example.com:

    <activity android:name=".MainActivity">
    <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="https"
    android:host="www.example.com"
    android:pathPrefix="/path" />
    </intent-filter>
    </activity>
    • android:autoVerify="true" :Ensures that Android verifies your domain is associated with your app.
    • Scheme and Host: Defines which URLs your app can handle (https://www.example.com/path in this case).
  • Step 2 - Prepare assetlinks.json File

    To verify your domain and associate it with your app, you need to host a file named assetlinks.json in the /.well-known/ directory of your domain.

    Example assetlinks.json file:

    [{
    "relation": ["delegate_permission/common.handle_all_urls"],
    "target": {
    "namespace": "android_app",
    "package_name": "com.example.app",
    "sha256_cert_fingerprints":
    ["14:6D:E9:83:C5:73:06:50:D8:EE:B9:95:2F:34:FC:64:16:A0:83:42:E6:1D:BE:A8:8A:04:96:B2:3F:CF:44:E5"]
    }
    }]
    • package_name: The package name of your Android app.
    • sha256_cert_fingerprints: The SHA-256 fingerprint of your app’s signing certificate. This field supports multiple fingerprints, such as debug and production builds. You can use the following command to generate the fingerprint via the Java keytool: keytool -list -v -keystore my-release-key.keystore
    • Host this file at https://www.example.com/.well-known/assetlinks.json
  • Step 3 - Declare Website Associations

    Ensure that your website declares the association with your app by hosting the assetlinks.json file. This lets Android verify that the website and your app are linked.

    • Upload the assetlinks.json file to your website at https://www.example.com/.well-known/assetlinks.json
    • Ensure the server has appropriate permissions and serves the file with application/json content type.
    • The assetlinks.json file must be accessible over an HTTPS connection, regardless of whether your app's intent filters declare HTTPS as the data scheme.
    • The assetlinks.json file must be accessible without any redirects (no 301 or 302 redirects).
  • Step 4 - Read Data from Incoming Intents

    When a user clicks a link that your app handles, you can extract the data from the incoming intent in your activity.

    • Example


      @Override
      protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      Uri data = getIntent().getData();
      if (data != null) {
      String url = data.toString();
      // Handle the incoming URL
      }
      }


  • Step 5 - Test and Verify

    Once all the steps are implemented, test the App Links by clicking a link that matches the intent filters. You can use the App Link Assistant in Android Studio to generate test URLs and verify the configuration.

Note: For more detailed exploration, please refer to the official Android documentation on App Links: Handling Android App Links