firebase-admin-java icon indicating copy to clipboard operation
firebase-admin-java copied to clipboard

Android device only receive 1 notification when offline.

Open lkdGologic opened this issue 2 years ago • 2 comments

My app sends non-collapsible push notification. When push notification are sent while device is online, everything works fine. Notifications are sent one by one. The problem is that if the device is offline (closed or airplane mode) only the last notification sent is received when the device come back online.

A work around that seems to be popular online is to generate unique collapseKey to force firebase to push notification in separate "collapse group". I know the limit is only 4 collapse key, but it is enough notifications for the app I'm building.

I've achieved the desired result on IOS by settings my apns-collapse-id to a random UUID for each notifications but now that I'me trying with android it doesn't seems to work.

I uses Firebase-admin version 9.1.1

<dependency>
      <groupId>com.google.firebase</groupId>
      <artifactId>firebase-admin</artifactId>
      <version>9.1.1</version>
</dependency>

This library uses FCM HTTP v1 endpoint

The collapseKey fields works. When setting it with this function : AndroidConfig.builder().setCollapseKey("non_unique_collapse_key").build()

The notifications are overwritten.

If I set it like this : AndroidConfig.builder().setCollapseKey(UUID.randomUUID().toString()).build()

All notification are sent separately.

The problem is that if I put my android to airplane mode, send myself 3 notifications (with 3 different collapse_key) When I put my device back online, I only receive the last notification sent.

The same cannot be said for IOS.

I set my notification like so :

ApnsConfig.builder().putHeader("apns-collapse-id", collapseKey)
        .setAps(Aps.builder().setAlert(
            ApsAlert.builder().setTitle(title).setBody(notificationContent).build()).build())
        .build();

and when I put my iphone back online, I receive 3 notifications.

lkdGologic avatar May 24 '23 17:05 lkdGologic

I guess my question now that I've edited the ticket would be : why is the apns-collapse-id working differently then the collapse_key

lkdGologic avatar May 24 '23 18:05 lkdGologic

Any solution guys ??

atultiwaree avatar Aug 03 '23 08:08 atultiwaree