使用node-gcm发送android通知而不折叠它们

我使用node-gcm向Android设备发送通知,在某些情况下,我需要发送带有通知的图像作为缩略图显示,如下所示: 缩略图通知

有时我需要发送没有缩略图的通知。 使用下面的代码,我可以发送通知中的图像,问题是当另一个通知收到时,他们崩溃,使新的一个覆盖已经存在的通知:

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

但是,如果我设置如下的消息,我不能find一种方式发送图像,但通知不会崩溃,所有这些都出现。 另一个问题是,在这个版本中,led不会激活:

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

我想要的是通过缩略图发送通知的方式,它不会覆盖之前的通知。

编辑:我忘了提及,即时通讯与cordova使用ionic framework,所以我不能pipe理设备中的通知,除非有办法通过这些框架来做到这一点。 提前致谢!

在查找node-gcm问题时,我find了解决scheme,有一个名为“notId”的参数,用于将ID添加到通知中。

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

通知显示的pipe理是在设备上完成的。 您必须确保您在Android上为每个通知设置了不同的NOTIFICATION_ID,否则最后一个将始终replace之前的NOTIFICATION_ID。

 // Sets an ID for the notification - make sure to change this for different notifications int mNotificationId = 001; // Gets an instance of the NotificationManager service NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); // Builds the notification and issues it mNotifyMgr.notify(mNotificationId, mBuilder.build());