I'm sending push notifications from FCM to an Android device, this is done by sending a POST message to FCM containing a JSON body.
If I send the same JSON body twice, the Android device will show two notifications (or three, or four, ...). But i want it to show only one.
The "collapse_key" should solve this, right? (FCM Documentation)
But where or how should it be inserted?
This SO question answers this but no example is given: Can FCM notification on Android overwrite previous one?
Current JSON body:
{
"notification": {
"title": "MyAPP",
"body": "Open MyAPP to access your data",
"click_action" : "OPEN_MAINACTIVITY",
"icon": "ic_launcher_red",
"color": "#ff0000"
},
"data": {
"extra1":"sample1",
"extra2":"sample2"
},
"registration_ids":[
"--my_id--"
]
}
I have tried in many ways to include the "collapse_key" but no luck so far. Still multiple notifications. Any help is welcome.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…