BlueS
BlueS

Reputation: 199

Send payload notification with node-gcm to android device

I'm using node-gcm to send notification to android device via GG GCM. The problem is, when I send 2 or more messages, they overlap on each others (the old message disappear and new message replace it). 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. This is the code for sending message, I had removed the collapse_key as GG say in their guide:

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!

Upvotes: 4

Views: 2549

Answers (1)

Eran
Eran

Reputation: 394156

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);

Upvotes: 4

Related Questions