Search code examples
androidkotlindeep-linking

Kotlin - Deep link to open my app but without dialog


I'm looking for a way to open my app from a link with parameter. I used deep link to do this, but when I click the link I have a dialog to choose between my app and the internet browser. How to directly open my app without this dialog ?

here is my code in manifest :

  <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" />
                <data android:host="my.application.app" />
            </intent-filter>

my link looks like :

https://my.application.app?param=1234

Thanks for your help


Solution

  • From the Official Android Documentation

    Starting in Android 12 (API level 31), a generic web intent resolves to an activity in your app only if your app is approved for the specific domain contained in that web intent. If your app isn't approved for the domain, the web intent resolves to the user's default browser app instead.

    The dialog appears because both your app and the web browser can handle the link. To prevent this dialog and have your app open directly, you need to configure Android App Links and verify your domain ownership.

    To establish trust between your app and your domain, host a file named assetlinks.json on your domain:

    • Place the file at this path: https://my.application.app/.well-known/assetlinks.json

    Example content for assetlinks.json:

    [
      {
        "relation": ["delegate_permission/common.handle_all_urls"],
        "target": {
          "namespace": "android_app",
          "package_name": "your.package.name",
          "sha256_cert_fingerprints": [
            "your-app-signing-certificate-fingerprint"
          ]
        }
      }
    ]
    

    make sure to replace:

    • your.package.name with your app’s package name.
    • app-signing-certificate-fingerprint with the SHA-256 fingerprint of your signing key.

    You can use the following command to test deep links:

    adb shell am start -W -a android.intent.action.VIEW -d "https://my.application.app?param=1234" your.package.name
    

    Ensure that your app handles the link without showing a dialog.

    And lastly, run the following command to confirm domain verification:

    adb shell pm get-app-links your.package.name
    

    If the domain is verified, the output will list your domain under verified.

    P.S: I highly recommend checking the Verify Android App Links guide in the documentation. It provides comprehensive steps and troubleshooting tips that can help you resolve similar issues effectively.


    For Offline Use or Without a Domain

    If you don't have a domain or need an offline solution, you can stick to deep links without using android:autoVerify. That said, if multiple apps can handle the link, users will still get the chooser dialog.

    Depending on what you want to achieve, you can use a custom scheme (myapp://open?param=1234) to avoid the chooser dialog entirely. This works well for app-specific links but won’t work in browsers or with standard web URLs.

    • Example: Use it in QR codes, app-to-app communication, or as embedded links in other apps.