I'm having some difficulties sending an argument through a PendingIntent
of a notification using NavDeepLinkBuilder
. I'm able to get the destination Activity
to launch by clicking the notification, but the Activity
's Intent
doesn't contain the argument value that I passed it through the NavDeepLinkBuilder
. The Intent
instead returns the defaultValue
that I set in the nav graph - "noJobId".
Notification creation:
val notification =
NotificationCompat.Builder(context, context.getString(R.string.notification_channel_id_new_job))
...
.setContentIntent(
NavDeepLinkBuilder(context)
.setComponentName(NewJobDetailsActivity::class.java)
.setGraph(R.navigation.main_graph)
.setDestination(R.id.newJobDetailsActivity)
.setArguments(
NewJobDetailsActivityArgs.Builder()
.setJobId(event.jobId)
.build()
.toBundle()
)
.createPendingIntent()
)
.build()
notificationManager.notify(notificationId, notification)
The context
used in the notification is the FirebaseMessagingService
.
Destination Activity
onCreate()
:
val jobId: String = NewJobDetailsActivityArgs.fromBundle(intent?.extras).jobId
main_graph.xml
Nav graph:
<navigation
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_graph"
app:startDestination="@id/jobsFragment">
<fragment
android:id="@+id/jobsFragment"
android:name=".ui.jobs.JobsFragment"
android:label="JobsFragment">
<action
android:id="@+id/action_jobsFragment_to_newJobDetailsActivity"
app:destination="@id/newJobDetailsActivity" />
</fragment>
<fragment
android:id="@+id/historyFragment"
android:name=".ui.history.HistoryFragment"
android:label="HistoryFragment" />
<fragment
android:id="@+id/profileFragment"
android:name=".ui.profile.ProfileFragment"
android:label="ProfileFragment" />
<activity
android:id="@+id/newJobDetailsActivity"
android:name=".ui.job.NewJobDetailsActivity"
android:label="activity_new_job_details"
tools:layout="@layout/activity_new_job_details">
<argument
android:name="jobId"
android:defaultValue="noJobId" // just for testing
app:argType="string" />
</activity>
</navigation>
Has anyone else run into this issue? I have a feeling it's a bug with the Navigation component, but I'm not 100% sure yet. Curious if there's something I'm missing here.
Dependencies: android.arch.navigation:navigation-fragment-ktx:1.0.0-alpha06, android.arch.navigation:navigation-ui-ktx:1.0.0-alpha06
Plugin: androidx.navigation.safeargs