Grisgram
Grisgram

Reputation: 3243

Firebase merge similar notifications in Android

We are using Firebase in a SIP app to send us missed call notifications and chat notifications whenever the app was offline.

While sending and receiving works fine, we have the effect on the Android client, that 5 missed calls obv produce 5 missed-call-notifications, filling up the notification bar on the client device.

How can we merge those notifications together, to just show a single "5 missed calls" notification?

Is there any additional flag (like grouping) we can put in the data or notification part of the message?

Here is an example of our current missed call notification:

{
    "to":"<<FCMToken>>",
    "priority":"high",
    "notification":{
        "title":"<<Displayname-of-Caller>>",
        "text":"<<Date-and-time-of-call>>", 
        "icon":"icon_notification_missed",
        "click_action":"MISSED_CALL"
    },
    "data":{
        "type":"sip-call-missed"
    }
}

So what's the trick in combining them together as one?

Upvotes: 1

Views: 3144

Answers (1)

Grisgram
Grisgram

Reputation: 3243

We found the correct solution. There are more existing keywords for the notification content. The one we needed was "tag". We can even localize the client-side text of the notification by supplying a resource name in loc keys.

Here is a correct message that can be bundled together:

{
"to":"<<FCMToken>>",
"priority":"high",
"notification":{
    "title_loc_key":"notification_missed_call",
    "tag":"MISSED_CALL",
    "body_loc_key":"notification_missed_call_multiple",
    "body_loc_args":["<<missed_call_count>>"],
    "icon":"icon_nav_main_chat",
    "click_action":"MISSED_CALL"
},
"data":{
    "type":"sip-call-missed"
}
}

The tag will be merged by the client ... say: they will replace each other. Whenever a notification with a tag arrives, it replaces all other existing notifications with the same tag. So the trick here is, to supply a running count <<missed_call_count>> (which the server has to count), so the client can show an increasing number, like "5 missed calls". The string "%d missed calls" is stored in the client side string resource named "notification_missed_call_multiple".

Upvotes: 7

Related Questions