4

Let's say I have the following buildType section in my Gradle file:

buildTypes {
    debug {
        ...
        resValue "string", "DEEPLINK_EXAMPLE", "appnamedebug://detail/{detail_id}"
        ...
    }
    release {
        ...
        resValue "string", "DEEPLINK_EXAMPLE", "appname://detail/{detail_id}"
        ...
    }
  }

I wanted to use the generated String resource as a deeplink in my Jetpack Navigation XML file as follows:

<deepLink app:uri="@string/DEEPLINK_EXAMPLE" />

I've tried something similar to this, but the Intent Filters don't show up when I looked at the output file from ./adb shell dumpsys package r.

Is this even possible in the first place? If it is, is there something I missed?

Gensoukyou1337
  • 1,507
  • 1
  • 13
  • 31
  • does [this](https://developer.android.com/guide/navigation/navigation-deep-link#implicit) help? Seems to be doable if you define the [argument](https://developer.android.com/guide/navigation/navigation-pass-data#define_destination_arguments) linking to the `R.string` and then uri could use the argument – Stachu Aug 24 '20 at 09:41
  • I don't think the fragment's argument, even with a default value, can be used as the URI of a Deeplink. – Gensoukyou1337 Aug 24 '20 at 10:43

2 Answers2

3

That method in the question just leads to the manifest having the intent filter as follows:

<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:scheme="http" />
    <data android:scheme="https" />
    <data android:host="string" />
    <data android:path="/DEEPLINK_EXAMPLE" />
</intent-filter>

I guess it's a pipe dream then.

Well, in the end I had to resort to the previous method: copying the Navigation Graphs to the debug and release source sets and set the deeplink URIs there accordingly.

So the Nav Graph in the debug source set would have this:

<deepLink app:uri="appnamedebug://detail/{detail_id}" />

While the Nav Graph in the release source set would have this:

<deepLink app:uri="appname://detail/{detail_id}" />

I'm actually not sure whether to keep the Nav Graph in the main source code, or remove it so the ones in the debug/release source sets have precedence.

Gensoukyou1337
  • 1,507
  • 1
  • 13
  • 31
1

As far as I know, this is not possible.

The previous answer says everything, but for clarity I want to add this example:

If you add to nav_graph:

<deepLink
    android:id="@+id/myLink"
    app:uri="@string/my_link_uri"
/>

It will be naively processed in the merged manifest as:

<intent-filter>
    <data android:host="string" />
    <data android:path="/my_link_uri" />
</intent-filter>

Therefore illustrating that string resources are not parsed correctly by the Navigation component.

Luke Needham
  • 3,373
  • 1
  • 24
  • 41