Sending several remote push notification while in airplane mode, when reconnect only receive the last one

Viewed 483

I'm trying to implement remote push notification on my android application using FCM, it works perfectly when there's an internet connection. But when putting the device in airplane mode, then sending several remote push notifications, then reconnect back I only receive the latest one.

I have tried changing the TTL in the payload, using differents collapse key and changing priority. Nothing worked. Here's a sample of my notification payload:

{"GCM": "{ \"notification\": { \"text\": \"test\",  \"title\": \"Titre\" },\"data\": { \"time_to_live\": 3600,\"collapse_key\":\"deals\"}, \"priority\": \"high\" }"}

FYI: The notification itself is sent from AWS SNS to FCM.

Anyone know the reason we only receive the latest one and how to make it so that we receive everything?

2 Answers

You should not use collapse_key. As it is stated in documentation:

A non-collapsible message denotes that each individual message is delivered to the device. A non-collapsible message delivers some useful content, as opposed to a collapsible message like a content-free "ping" to the mobile app to contact the server to fetch data.

...

A collapsible message is a message that may be replaced by a new message if it has yet to be delivered to the device.

To mark a message as collapsible on Android, include the collapse_key parameter in the message payload. FCM allows a maximum of four different collapse keys per Android device to be used by the app server at any given time. In other words, the FCM server can simultaneously store four different collapsible messages per device, each with a different collapse key. If you exceed this number, FCM only keeps four collapse keys, with no guarantees about which ones are kept.

In other words: FCM will replace the latest not received push notification content with a new push notification request content if their collapse_key is the same.

And a little screenshot as pasting a table is not convenient:

Should you use collapsible messages or not? A table with explanations is shown for you to decide.

When you display the notification are you using the same number in notificationId? If so, the notifications with same ids will override each other and only display the last one. You need to have a static integer here and increment it every time you use this variable. Refer here

notificationManager.notify(notificationId, builder.build());
Related