An implicit deep link from a notification in JetpackNavigation library
Asked Answered
Y

1

14

I'm trying to implement an implicit deep link handling in my application, but the following code doesn't work out and onNewIntent in my single activity isn't calling, but always startDestination from navigation graph is opening.

In my navigation graph, I have the following deep link for a fragment

 <deepLink
        android:id="@+id/deepLink"
        app:uri="people/{uuid}" />

Then I added the nav. graph to manifest file between the activity tag

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

After I put onNewIntent implementation to MainActivity and it looks like

 override fun onNewIntent(intent: Intent?) {
    super.onNewIntent(intent)
    findNavController(R.id.fragmentContainer).handleDeepLink(intent)
}

Creating of a pending intent is happening like:

val intent = Intent(context, MainActivity::class.java).apply {
    flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
    data = Uri.parse("people/$uuid")
}

val pendingIntent = PendingIntent.getActivity(
    context,
    PENDING_INTENT_REQUEST_CODE,
    intent,
    0
)

And finally the dialog creation

val notification = NotificationCompat.Builder(context, CHANNEL_ID)
        // not important
        .setContentIntent(pendingIntent)
        .setPriority(NotificationCompat.PRIORITY_DEFAULT)
        .build()

NotificationManagerCompat
    .from(context)
    .notify(Random.nextInt(), notification)
Youthen answered 1/5, 2020 at 15:37 Comment(2)
did you find any solution?Octastyle
were you able to solve?Chalkstone
M
0

I think first your scheme is wrong it should be something like <scheme_name>://people/{uuid}

Masseur answered 3/7, 2021 at 9:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.