Search code examples
androidandroid-architecture-componentsfirebase-dynamic-linksandroid-architecture-navigation

Should I treat firebase dynamic links in a way that differs from treating deep links?


I'm trying to use Firebase dynamic links with android navigation component, The problem is am trying to specify a fragment to automatically open when the link is opened but what opens is the start destination of the specified graph not the fragment desired

I've tried to change the link yo be www.google.com instead of the actual dynamic link. Surprisingly it worked !!

here is the manifest code for the activity that has the fragment in its navigation graph

    <activity android:name=".vvm.authentication.view.AuthenticationActivity" >
        <intent-filter android:label="New Password">
            <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="example.page.link"/>
        </intent-filter>
    </activity>

and here is the navigation graph definition of the fragment I desire to open directly

<fragment
    android:id="@+id/newPasswordFragment"
    android:name="com.example.fatorty.vvm.authentication.view.NewPasswordFragment"
    android:label="fragment_new_password"
    tools:layout="@layout/fragment_new_password">
    <deepLink
        android:id="@+id/deepLink"
        app:uri="https://example.page.link"
        android:autoVerify="true"/>
</fragment>

when I replace android:host="example.page.link" in the manifest and app:uri="https://example.page.link" in the fragment definition with android:host="www.google.com" and app:uri="https://www.google.com" the app behave as desired !

any suggestions ?

Note: the full link of Firebase is

https://example.page.link/?link=https://example.page.link


Solution

  • Finally figured out the solution. In case of dynamic link which Firebase generates, the link consists of 2 parts. The prefix:

    https://example.page.link/?link=

    which the system uses to direct to google play or custom website and so on and the suffix:

    https://example.page.link

    which the app recive if installed. If you're using the legacy app architecture, Activities and intents, the intent filter receives the suffix and normally behave.

    In case of navigation component and navigation graph, you have to put the prefix + the suffix in the deep link uri attribute for the app to behave correctly like this:

    <fragment
        android:id="@+id/newPasswordFragment"
        android:name="com.example.example.vvm.authentication.view.NewPasswordFragment"
        android:label="fragment_new_password"
        tools:layout="@layout/fragment_new_password">
        <deepLink
            android:id="@+id/deepLink"
            app:uri="https://example.page.link/?link=https://example.page.link"
            android:autoVerify="true"/>
    </fragment>