Is there a way to tell manifest merger not to add path data to intent-filter

Viewed 184

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?

2 Answers

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.

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

Related