I'm sending notifications to users Android devices though the Firebase Notification console and I notice that even if I send 10 different notifications while the user device is offline, once the user goes online she/he will receive all 10.
However in Firebase documentation it is stated that:
FCM allows a maximum of four different collapse keys per device to be used by the app server at any given time. In other words, the FCM connection server can simultaneously store four different collapsible send-to-sync 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.
So shouldn't the user receive only 4 notifications? Am I missing something? (I am not extending the FirebaseMessagingService
, I leave the notification handling to the SDK)
UPDATE: If you don't specify a collapse key in the Firebase notifications console, it seems that an implicit collapse key is assigned to the notification and that is the package name of the app. I've tested that by checking all key/value pairs of the getIntent().getExtras()
key set, once I launch the app by tapping on the notification. And indeed, I am getting a collapse_key
key with the value of the package name, even if I haven't specified one.
UPDATE 2: I tried to handle the notifications by extending the FirebaseMessagingService
, so that I receive the messages from the notifications console, when the app is in the foreground. I receive the notification message and I manually display a notification to the user. And guess what. Collapse keys work great! I receive a single notification even if I send multiple notifications with the same collapse key. BUT this happens obviously only when the app is in the foreground, because the Firebase SDK doesn't call the onMessageReceived()
when the app is in the background, but instead it handles the notification itself. Does that mean that this is a bug of the Firebase SDK? (since the issue happens only when the notification is shown by the SDK)
So question remains, why do I receive all 10 notifications since each notification has the same collapse key? Maybe an FCM bug?