I'm sending notifications to an android device using node-gcm, and in some cases, I need to send an image with the notification to display as a thumbnail, like so:
notification with thumbnail
And sometimes I need to send notifications without the thumbnail. With the below code I can send the image in the notification, the problem is when another notification is received, they collapse, making the new one overwriting a notification that was already there:
var message = new gcm.Message({
"data" : {
"title" : "Test",
"message" : "Test message!",
"priority" : 2, // Highest priority.
"ledColor" : [255, 0, 0, 1],
"content-available": "1",
"image": req.body.notificationImageUrl, //<-- image URL
},
});
var message = new gcm.Message({
data: {
"priority" : 2, // Highest priority.
"content-available": "1",
"image": req.body.notificationImageUrl, // <-- image URL
},
notification:{
title: "Test",
body: "Test message!",
color: "#892121",
sound: 'default',
vibrationPattern: [300, 150, 300], // Vibrate for 300ms then wait 150ms and then vibrate for 300ms.
ledColor: [255, 0, 0, 1], // <-- this does not work
},
});
While going through the node-gcm issues I found the solution, there is a parameter called "notId" to add a ID to a notification.
var message = new gcm.Message({
"data": {
"title": "Test",
"message": "Test message!",
"priority": 2, // Highest priority.
"ledColor": [255, 0, 0, 1],
"content-available": "1",
"image": req.body.notificationImageUrl,
"notId": parseInt(Math.random() * new Date().getSeconds(), 10), // <-- this solved the problem
},
});