Firebase发送多个推送通知,而不是堆叠或替换

时间:2016-10-07 18:32:06

标签: android firebase push-notification notifications firebase-notifications

我正在尝试使用新的推送通知堆栈或将其替换为Android系统托盘。

我不知道如何执行此操作,因为推送通知正在发送回数据和通知对象,并且据我所知,通知直接发送到系统托盘。如果是这样,我如何阻止通知独立出现。有些用户会收到5-10个通知,而且会继续推升。

编辑:

我尝试过collapse_key,但它仍然没有用相同的密钥替换先前的通知......我在这里做错了吗?

method: 'POST',
                            uri: 'https://gcm-http.googleapis.com/gcm/send',
                            headers: {
                                'Content-Type': 'application/json',
                                'Authorization': authorize //GOOGLE API KEY
                            },

                            body: JSON.stringify({
                                "registration_ids": [otherUserResult.reg_id],

                                "collapse_key": "follow",
                                "data": {
                                    "notifyToUserId": to,
                                    "notifyFromId": from,
                                    "notifyMsg": msg,
                                    "notifyItemPicture": itemPic,
                                    "notifyItemName": itemName,
                                    "notifyFromName": fromName,
                                    "notifyType": type,
                                    "dateNotified": dateNotified


                                },
                                "notification": {
                                    "title": fromName,
                                    "body": notifyMsg,
                                    "icon"  : "ic_pushnotify"
                                },
                                "priority": "high",
                                "content_available": true

1 个答案:

答案 0 :(得分:0)

对我来说,当我加入“通知”时,我就会工作。 2行:

collapse_key: 'your_app_unique_string',
tag: 'your_app_unique_string'

所以完整的代码是:

var payload = {notification: {
                                        title: "Mensaje de "+message.name,
                                        body: message.text,
                                        sound: "default",
                                        collapse_key: 'charlero',
                                        tag: 'charlero'
                                    }
                                };