12

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)
gromyk
  • 570
  • 5
  • 17

1 Answers1

0

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

Daksh Semwal
  • 99
  • 2
  • 11