I am using the Navigation Component and I am trying to trigger an explicit deep linking to a specific destination, represented by a Fragment, when the user taps on a notification.
According to the documentation a pending intent can be create like this:
val bundle = bundleOf("id" to "1234")
val pendingIntent = NavDeepLinkBuilder(context)
.setGraph(R.navigation.nav_graph)
.setDestination(R.id.myDestination)
.setArguments(args)
.createPendingIntent()
Where nav_graph is defined as follow:
<fragment
android:id="@+id/myDestination"
android:name="MyFragment">
<argument
android:name="id"
app:argType="string" />
<deepLink app:uri="myApp://myFragment?id={id}" /> // Removing this line it works fine
</fragment>
I would then use the pendingIntent into the notification using the NotificationCompat.Builder
with:
.setContentIntent(pendingIntent)
When I tap on the notification the right destination is actually opened, but the value args.id
would be "null" (not null
, but a string with "null" value. In my fragment I have
private val args by navArgs<MyFragmentArgs>()
...
override fun onCreate(saveInstanceState: Bundle?) {
args.id // The string value is "null".
}
However if I remove the <deepLink>
from the fragment then it will work. The problem is that I need both implicit and explicit deep links. Is there a way for supporting both with Navigation Component?