Jetpack compose navigation can't handle deeplink from pendingIntent

160 views Asked by At

When I send a data on my firebase notification and after verify that's exist I create a pendingIntent and include my intent to navigate.

   private fun sendNotification(messageBody: String, title: String?, bookingId: String?) {
       val intent = if (bookingId.isNullOrEmpty()) {
           Intent(this, MainActivity::class.java)
       } else {
           Intent(
               Intent.ACTION_VIEW,
               Uri.parse("https://website.com/booking?b=$bookingId")
           )
       }

       intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
       val pendingIntent = PendingIntent.getActivity(
           this, 0, intent,
           PendingIntent.FLAG_IMMUTABLE
       )

       val channelId = getString(R.string.default_notification_channel_id)
       val defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
       val notificationBuilder = NotificationCompat.Builder(this, channelId)
           .setSmallIcon(R.drawable.myicon)
           .setContentTitle(title)
           .setContentText(messageBody)
           .setAutoCancel(true)
           .setSound(defaultSoundUri)
           .setContentIntent(pendingIntent)

       val notificationManager =
           getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager

       if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
           val channel = NotificationChannel(
               channelId,
               title,
               NotificationManager.IMPORTANCE_DEFAULT
           )
           notificationManager.createNotificationChannel(channel)
       }

       notificationManager.notify(0, notificationBuilder.build())
   }

This is my notification. Also I have a navigation and I have a specific screen to handle the deeplink.

composable("bookingScreen", deepLinks = listOf(navDeepLink {
            uriPattern = "https://website.com/booking?b={bookingId}"
            action = Intent.ACTION_VIEW
        })) { MyScreen() }
}

The problem is always when I click on notification just open the mainActivity.

The deeplink have to work because if I use the App Link Assistant on Android Studio it works, and if I call the navigation controller to navigate to the current URI works too. Only doesn't work on the pending intent.

0

There are 0 answers