Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

json - Android FCM - how to show only one notification

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...