3

I'm using navigation component and navigation graph for handling deeplinks. I've added deeplinks to my destinations like below

<deepLink app:uri="example://foo" />

Intent Filter documentation mentions:

If a filter specifies a scheme and an authority but no path, all URIs with the same scheme and authority pass the filter, regardless of their paths.

According to this, a uri like example://foo should match my deeplink. But manifest merger adds this line to my intent filter, even if don't add any path to my uri:

<data android:path="/" />

So only a example://foo/ is matched. Is there a way to tell manifest merger or navigation graph to remove this data element from my intent filter?

osrl
  • 8,168
  • 8
  • 36
  • 57
  • "all URIs with the same scheme and authority pass the filter, regardless of their paths." means your pathless intent filter also matches `example://foo/anything`, which is not what your `app:uri` says it should match – ianhanniballake Sep 01 '21 at 03:47

2 Answers2

1

Android does not allow you to create an intent-filter that matches only no path at all: it is impossible to write an intent-filter that matches example://foo but not example://foo/something_random.

As per this issue, this is intentional: using a pathless uri like app:uri="example://foo" means you want to match exactly that empty path - i.e., / and not match every single path with that authority and scheme.

ianhanniballake
  • 191,609
  • 30
  • 470
  • 443
  • thanks ian. I understand what you mean. But since we only use scheme and host this should not be a problem for us. This is also the case for us when we didn't use navigation component. We added `intent-filter`s to our manifest like `example://screenA` `example://screenB` and that worked for us. – osrl Sep 02 '21 at 11:31
0

I also encountered this annoying thing.

I don't agree with the last answer since you can simply create your own intent-filter that only declare scheme and host.

I consider it a bug in the nav-graph tag processing (the one you nest in you activity tag).

Simple remove:

<nav-graph android:value="@navigation/your_nav_graph" />

And replace it with intent filter you create manually:

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

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

    <data
        android:host="foo"
        android:scheme="example" />

</intent-filter>

I know I'm basically telling you to not-use auto intent-filter creation navigation feature but it's the only way that I found that navigation component accepts

Shlomi Katriel
  • 2,103
  • 1
  • 7
  • 20
  • I don't really want to handle deeplinks manually. That's one of the reasons why we use navigation component. Our simple solution is adding "/" at the end of host string. – osrl Sep 02 '21 at 11:35
  • I can respect that :). In my case the actual link could not be changed so I had no choice. Good Luck. – Shlomi Katriel Sep 02 '21 at 11:44