Search code examples
androidandroid-intentandroid-architecture-navigationandroid-deep-link

Android Deep link opens with "Launch URL" but not with typing exact url


I've been using Android's implicit deep links and I've defined my deep link directly inside my navigation graph.

The problem is when I use "Launch Options" in configurations like below my deep link will open the fragment just fine, but when I type the exact URL it won't work (btw I tried typing with http, https, without it, in a note app and in the browser directly).

enter image description here

Any guesses why this happens?

Some parts of my code related: navigation_graph :

    <fragment
        android:id="@+id/usedPriceFragment"
        android:name="UsedPriceFragment"
        android:label="UsedPriceFragment">
        <argument
            android:name="clearCache"
            android:defaultValue="false"
            app:argType="boolean"
            app:nullable="false" />
        <deepLink
            android:id="@+id/deepLink"
            app:action="ACTION_VIEW"
            app:mimeType="type/subtype"
            app:uri="example.com/example/prices/used" />
    </fragment>

manifest:

<activity
            android:name="activity.MainActivity"
            android:launchMode="singleTask"
            android:windowSoftInputMode="adjustResize">

            <intent-filter android:autoVerify="true">
                <action android:name="android.intent.action.VIEW" />
                <data android:pathPrefix="/example/prices" />
            </intent-filter>
            <nav-graph android:value="@navigation/navigation_graph_main" />

Edit: Detailed version: The system asks me if I want to open the URL with my app. I click yes and then the home page starts up instead of the fragment I wanted to open.


Solution

  • Turns out when opening an activity in singleTask mode you need to handle the received intent manually. So adding this line of code fixed the problem.

    if (mainActivity.tabManager.findActiveNavController()?.handleDeepLink(intent) == true) {
                return
            }