简体   繁体   English

将带有node-gcm的有效负载通知发送到android设备

[英]Send payload notification with node-gcm to android device

I'm using node-gcm to send notification to android device via GG GCM. 我正在使用node-gcm通过GG GCM向Android设备发送通知。 The problem is, when I send 2 or more messages, they overlap on each others (the old message disappear and new message replace it). 问题是,当我发送2条或更多消息时,它们彼此重叠(旧消息消失,新消息替换它)。 And when I disconnect my device from internet, then send 2 messages, I connect to the internet and there is only one notification with the last message I had sent. 当我从互联网断开我的设备,然后发送2条消息,我连接到互联网,只有一个通知与我发送的最后一条消息。 This is the code for sending message, I had removed the collapse_key as GG say in their guide: 这是发送消息的代码,我已经删除了像GG在他们的指南中所说的collapse_key:

function sendNoti(content){

// with object values
var message = new gcm.Message({
    //collapseKey: 'cms',
    //delayWhileIdle: true,
    //timeToLive: 10,
    data: {
        news: content
    }
});
var sender = new gcm.Sender('MY KEY');
var registrationIds = [];
db.noti.find({}, function (err, getted) {
    getted.forEach(function (each) {
        registrationIds.push(each.regId);
    });

    /**
     * Params: message-literal, registrationIds-array, No. of retries, callback-function
     **/
    sender.send(message, registrationIds, 10, function (err, result) {
        console.log(result);
    });
})
}

Please help me out of this. 请帮我解决这个问题。 Thank you very much! 非常感谢你!

Your server code is not relevant to your problem. 您的服务器代码与您的问题无关。 Your client code is probably displaying the notification with a constant identifier. 您的客户端代码可能显示带有常量标识符的通知。 That causes each new notification to overwrite the previous one. 这会导致每个新通知覆盖前一个通知。

You have to change the notify method call from : 您必须从以下位置更改通知方法调用:

notificationManager.notify (CONSTANT_NOTIFICATION_ID, notification);

to : 至 :

notificationManager.notify (unique_identifier, notification);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM