0

I have used this How to get custom data from android firebase notification? solution for getting custom data from Firebase and it work only if Application is open, when Application is closed the custom data return empty String ""

Another question related if remove the code for notification from:

public void onMessageReceived(RemoteMessage remoteMessage) {

and application is closed i recevived always a notification but if open not?

I think if Application is open use my code but if closed what code use?

clauub
  • 1,134
  • 9
  • 19
J. Doe Cd
  • 69
  • 9

1 Answers1

1

The callback onMessageReceived is only called when the application is running ie its in foreground.

according to https://firebase.google.com/docs/cloud-messaging/android/receive

onMessageReceived is provided for most message types, with the following exceptions:

  • Notification messages delivered when your app is in the background.

In this case, the notification is delivered to the device’s system tray. A user tap on a notification opens the app launcher by default.

  • Messages with both notification and data payload, both background and foreground:

In this case, the notification is delivered to the device’s system tray, and the data payload is delivered in the extras of the intent of your launcher Activity.

So the payload data you need to fetch using intent.getExtras()

purush
  • 559
  • 3
  • 12