Sobinscott
Sobinscott

Reputation: 531

FCM data message does not send latest data payload

I am sending data-message to my android application via FCM.But when I change the data payload structure,it does not seem to affect. The FCM payload is

{
"to" : "eF3lccIdYs4:APA91bHpC1xWNl4MZXXXX",
"data" : {
 "caller_name" : "Sobin Thomas",
  "room"    : "2000",
  "call_type" : "audio"

  }, 
"time_to_live" : 0
}

If I change it to

{
"to" : "eF3lccIdYs4:APA91bHpC1xWNl4MZXXXX",
"data" : {
 "**caller**" : "Sobin Thomas",
  "**room_number**" : "2000",
  "call_type" : "audio",
 **"call_time" : "2018-04-24 12:12:12",**

  }, 
"time_to_live" : 0
}

Old data payload is still getting in the mobile app. And of course the data payload values change

Upvotes: 1

Views: 774

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 598765

Firebase Cloud Messaging will try to deliver every message, not just the last one. What's likely happening is that your device is receiving multiple messages in short succession, and only displays one.

If you want new messages to replace older message, you'll need to specify a so-called collapse_key. From the documentation:

This parameter identifies a group of messages (e.g., with collapse_key: "Updates Available") that can be collapsed, so that only the last message gets sent when delivery can be resumed. This is intended to avoid sending too many of the same messages when the device comes back online or becomes active.

Upvotes: 1

Related Questions