Search code examples
androidflutterapplinksandroid-app-links

Android app link for multiple apps under same domain


I have two android apps - Application A and Application B. I also have a website which is hosting the applinks.json file and verified it works correctly - clicking on a link does take me to application A.

What I want to do:

I want to have the same website point to different applications, e.g. mywebsite.com/applicationA to link to Application A, and mywebsite.com/applicationB to link to Application B.

Both of the apps are defined inside assetlinks.json. However, what I've observed when using Google Pixel 6 is that it only allows for one of my applications to handle the app link at a single time. If I add the supported link for one app, it gets removed from the other one.

So the question is - is that possible? If so - how, if not, what is the correct approach for this type of arrangement?


Solution

  • If you have two separate apps with different package IDs (app IDs) and both are properly configured in the assetlinks.json file, theoretically, both apps should be able to handle the same app link. However, if only one app is consistently opened when the app link is clicked, maybe due to:

    Priority of Intent Filters: Each app may have different intent filters configured to handle the same app link. Android system decides which app to open based on various factors such as the specificity of the intent filter, priority, and order in which the apps were installed. Ensure that the intent filters in both apps are correctly configured and don't conflict with each other.

    If you want to open a specific app based on different URLs from the same domain, you can achieve this by configuring your intent filters differently for each app. Here's how you can do it:

    Configure Intent Filters in AndroidManifest.xml: In each app's AndroidManifest.xml file, define specific intent filters for the URLs you want the app to handle. You can specify different paths, hosts, or query parameters to differentiate between the URLs.

    For example, in App A's 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" android:host="yourdomain.com" android:pathPrefix="/appA/*" />
    </intent-filter>
    

    And in App B's 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" android:host="yourdomain.com" android:pathPrefix="/appB/*" />
    </intent-filter>
    

    App A will handle URLs with the path "/appA/" on yourdomain.com, while App B will handle URLs with the path "/appB/" on the same domain.

    Refer to the official document for more details Android Data Element