1

I have an Android app that's in the background. I've registered it with Firebase and have been able to successfully retrieve it's token, as well as sending messages to it via the Firebase Console Manager (FCM).

When I send test messages via FCM, when the app is in the foreground the

onMessageReceived(remoteMessage:RemoteMessage)

call back API for my FirebaseMessagingService derived class gets triggered. I can then call remoteMessage.notification!!.body and obtain it's payload. This is the documented behavior so it's working as expected.

When the app is in the background though (say I press the home key), and I send the test message, that event doesn't get called but instead a notification shows up on the Android device, which is also the expected behavior. So far so good.

However, when I click on the notification in the notification channel, it brings the app to the foreground. However, when the app is launched like that - how does one retrieve the push notification payload? The onMessageReceived isn't triggered, and I'm having a hard time finding the answer to this in Android's documentation.

Any indication as to how to obtain that?

Thanks

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Daltrey Waters
  • 325
  • 2
  • 14

2 Answers2

0

Turns out this question provided the answer i was looking for. TL;DR - look in the extras field in the intent variable of the Activity

Firebase (FCM): open activity and pass data on notification click. android

Daltrey Waters
  • 325
  • 2
  • 14
-1

Im not sure my solution below is best. But I think you can save the message to share preferences . And get it to another place it you want to you.

  override fun onMessageReceived(p0: RemoteMessage) {
   //TODO save it to share preferences
}

Give me another better solution if you find it. Thank you so much.

JackHuynh
  • 74
  • 5