Search code examples
androidfirebaseandroidxfirebase-dynamic-links

Navigation component seems to work only with short dynamic link (firebase)


Example: Long Dynamic Link

https://domaindebug.page.link/?link=https://www.website.com&apn=com.x.debug&isi=122...6&ibi=com.ios.x.debug&efr=1

Short Dynamic Link

https://domaindebug.page.link/register
<fragment
        android:id="@+id/fragment_register"
        android:name="com.x.presentation.feature.identification.view.RegisterFragment"
        tools:layout="@layout/fragment_register">
        <action
            ... />
        <argument
            android:name="code"
            android:defaultValue="@null"
            app:argType="string"
            app:nullable="true" />
        <deepLink
            android:id="@+id/deepLink"
            app:uri="https://domaindebug.page.link/register?code={code}" />
</fragment>

If I click on long dynamic link, nothing happens. How can I manage this? I also can't find any documentation about integrating firebase dynamic deeplink + navigation component


Solution

  • I have not seen any official integration of dynamic links with the navigation component so far. But it's pretty simple to integrate them manually by fetching the link with help of FirebaseDynamicLinks and passing it to the NavController:

    FirebaseDynamicLinks.getInstance()
                .getDynamicLink(intent)
                .addOnSuccessListener(this) { link ->
                    findNavController(R.id.nav_host_fragment).handleDeepLink(Intent().apply {
                        data = link?.link
                    })
                }
    

    Please check out the sample project I've created to show the idea. It handles deep links in a separate activity to make UI smoother, but hands over the link to the navigation component for handling.