1

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.

Maryam Mirzaie
  • 536
  • 6
  • 24

2 Answers2

1

Testing deep links by typing them in the browser isn't generally a good idea. The browser will often try to handle the URL itself, and won't pass it to the OS.

You should instead send the intent via ADB itself, like so:

adb shell am start -a android.intent.action.VIEW \
    -c android.intent.category.BROWSABLE \
    -d "http://domain.name:optional_port"

Further information is available in the documentation for app links.

As a side note, I'm assuming example.com in your code is placeholder text. If not, when you use autoVerify="true" it must be to a domain you control, and have set up verification for.

Jake Lee
  • 7,549
  • 8
  • 45
  • 86
  • Thank you for putting the time to write an answer. Yes, the `example.com` is just a placeholder; but even with the command you wrote, my fragment is not being opened and there is not log inside LogCat. I typed `https://example.com/example/prices/used` exactly but still no luck. – Maryam Mirzaie May 05 '21 at 15:04
  • Actually, 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. – Maryam Mirzaie May 05 '21 at 15:06
  • That's much more promising, at least it's in your app! Not sure I can help more, sorry, perhaps the `mimeType` needs checking? – Jake Lee May 05 '21 at 15:10
  • I tried removing it and that didn't work too. – Maryam Mirzaie May 05 '21 at 15:14
  • What if you remove the `intent-filter` you've added, and rely on the autogenerated one? – Jake Lee May 05 '21 at 15:17
  • I just tried that too, still no luck :( It will open up the app home page though still. Is there anyway to check the generated files for a deep link? – Maryam Mirzaie May 05 '21 at 15:20
  • Out of ideas, sorry! Here: https://stackoverflow.com/questions/32087870/manifest-merger-it-is-possible-to-see-the-resulting-mixed-manifest – Jake Lee May 05 '21 at 15:22
  • Thank you for putting out you time :) – Maryam Mirzaie May 05 '21 at 15:28
  • I just found the problem, I posted the answer below :) – Maryam Mirzaie May 08 '21 at 08:31
1

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
        }
Maryam Mirzaie
  • 536
  • 6
  • 24