How to manage two different intent filter for android deeplink/applink?

1k views Asked by At

I have already an intent filter for my applink/deeplink. Sample code :

<activity android:name="com.XXXX.XXXX.XXXXXXXXXXXXActivity"
            android:enabled="true"
            android:excludeFromRecents="true"
            android:noHistory="true"
            android:theme="@android:style/Theme.Translucent"
            android:launchMode="singleInstance">
            <intent-filter android:autoVerify="true">
                <data android:scheme="http" />
                <data android:scheme="https" />
                <data android:host="www.xxxxxx.com" />
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
            </intent-filter>
</activity>

This intent filter does not make any link redirection from web browser to app because we don't have any path or pathPattern. We what our behaviour like that only. But for a new saml signin use case, we have to open saml sign in page in the web browser(not in app webview) and once signed in redirect back to app. So we want to use a pathPattern now. Now the problem starts. We have the same scheme and host. So if I create a new intent filter under the same activity with same scheme and host with pathPattern browser making all url redirection to app which I don't want at all. Sample code :

<activity android:name="com.XXXX.XXXX.XXXXXXXXXXXXActivity"
            android:enabled="true"
            android:excludeFromRecents="true"
            android:noHistory="true"
            android:theme="@android:style/Theme.Translucent"
            android:launchMode="singleInstance">
            <intent-filter android:autoVerify="true">
                <data android:scheme="http" />
                <data android:scheme="https" />
                <data android:host="www.xxxxxx.com" />
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
            </intent-filter>
                <data android:scheme="http" />
                <data android:scheme="https" />
                <data android:host="www.xxxxxx.com" />

                <data android:pathPattern="/ap/signin.*" />

                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
            </intent-filter>
</activity>

I have tried with a new activity and used the second intent filter there, but still the same problem. All the urls starts redirecting from the browser to app instead only /ap/signin url.

When I am only using the 2nd intent filter and removed the 1st intent filter, /ap/signin url only redirects from the browser to app, but all other deeplink/applink url stops working. This is kind of known to me.

Does anyone have a proper solution of this? With out breaking the existing flow how can I introduce a new pathPattern ?

1

There are 1 answers

6
The Dude On

You need to use "pathPrefix" so only ap/signin will open in your app

    <intent-filter>
            <data android:scheme="http" />
            <data android:scheme="https" />
            <data android:host="xxxxxx.com" />

            <data android:pathPrefix="/ap/signin/" />

            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
        </intent-filter>