I'm new with working with notifications in my app so please bear with me. I have a pending intent which will navigate to MainActivity when the user clicks on it. I want to change it so that it navigates to a fragment that has navigation arguments.
My code for pending intent
val notifyIntent = Intent(context, MainActivity::class.java).apply {
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
data = Uri.parse(uri)
}
return PendingIntent.getActivity(
context, 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT
)
Navigation action for my fragment
NavigationGraphMainDirections.actionGlobalManagePostFragment("data")
I don't know if I have to send the string of data with the notification and get it back with the pending intent. What is the solution here?
The best way to achieve what you want is to use an explicit deep link.
Create your pending intent as in:
val pendingIntent = NavDeepLinkBuilder(context)
.setGraph(R.navigation.nav_graph)
.setDestination(R.id.android)
.setArguments(args)
.createPendingIntent()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With