Search code examples
androiddeep-linkingfirebase-dynamic-linksbranch.io

Deep linking sometimes opens wrong activity


We're encountering some issue with the deep linking. We have two deep linking providers. Firebase and Branch. We have our users experiencing issue where they click Firebase link, lets say to open activity A, but instead it opens activity B (which is for Branch). Unfortunately we are not able to reproduce it, but it happens to some of our users. And when this happens, it's always reproduce-able for them.

This is the Firebase setting we have

<activity android:name=".activity.FirebaseActivity"
    android:screenOrientation="portrait">
    <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:host="firebase.page.link"
        android:scheme="https" />
    </intent-filter>
</activity>

and for Branch:

<!-- Branch URI scheme -->
            <intent-filter>
                <data
                    android:host="open"
                    android:scheme="branch" />

                <action android:name="android.intent.action.VIEW" />

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

            <!-- Branch App Links -->
            <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:host="branch.app.link"
                    android:scheme="https" />
            </intent-filter>
        </activity>

Solution

  • Finally found the issue that is causing this.

    We have the dynamic link domain as {firebase-dynamic-domain}.page.link. However, in some cases, when user gets redirected to the app, the link is showing as

    https://{your-project}.firebaseapp.com&...

    instead of

    https://{firebase-dynamic-domain}.page.link?link=https://{your-project}.firebaseapp.com&...

    To fix this, you can add the project name domain for the filter as well or catch this in the launcher activity

    <activity android:name=".activity.FirebaseActivity"
        android:screenOrientation="portrait">
        <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:host="firebase.page.link"
            android:scheme="https" />
        </intent-filter>
        <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:host="{your-project}.firebaseapp.com"
            android:scheme="https" />
        </intent-filter>
    </activity>