2

My app has push notification (FCM). When app runs in foreground,I can get data payload in onMessageReceived() function. When app runs in background or app was fully closed, onMessageReceived() function was not invoked. My question is, is possible to get data payload when app in background or closed?

Thanks in advance!

do87
  • 197
  • 2
  • 8
  • refer this link https://stackoverflow.com/questions/37711082/how-to-handle-notification-when-app-in-background-in-firebase –  May 10 '18 at 11:39

1 Answers1

0

If you want to receive data payload in your onMessageReceived() then you need to do change where you generating the notification(like at your server side),

You need to remove notification payload just need to send data payload If you send only data payload then its work like bellow one.

From

{"to":"[add your token]","notification":{"title":"[add title]","body":"[add your message]"},"priority":"high"}

TO

{"to":"[add your token]","data":{"title":"[add title]","body":"[add your message]"},"priority":"high"}

After doing this you will get notification perfectly

Dhaval Solanki
  • 4,589
  • 1
  • 23
  • 39