推送通知:不要替换旧的消息

时间:2015-10-20 07:11:58

标签: c# android json web-services push-notification

我已经向Android发送了推送通知,但新邮件的内容将取代旧邮件。怎么解决?

以下代码:

push.QueueNotification(new GcmNotification().ForDeviceRegistrationId("APA91bGZpTp6n3W29RjV_yN3ulNSnP2EAmqccfLQTRdBva_9D7Yy8S-uLqqZ0-gqEn0q2Xwb5o7-v0KEugGjYaX05--8UW17RT4piF5rU0uCjnIwzEc_rwiuo-KY-r1pRe4_ElD65bBExXn2KnbT0iwHTKZmDOqqXw")
.WithJson("{\"notId\":\"1\",\"type\":\"a\",\"caseid\":\"123\",\"contract\":\"a1\",\"title\":\"Message: Type a\",\"message\":\"[a1] \"}")
.WithTag("1"));


push.QueueNotification(new GcmNotification().ForDeviceRegistrationId("APA91bGZpTp6n3W29RjV_yN3ulNSnP2EAmqccfLQTRdBva_9D7Yy8S-uLqqZ0-gqEn0q2Xwb5o7-v0KEugGjYaX05--8UW17RT4piF5rU0uCjnIwzEc_rwiuo-KY-r1pRe4_ElD65bBExXn2KnbT0iwHTKZmDOqqXw")
.WithJson("{\"notId\":\"2\",\"type\":\"b\",\"caseid\":\"456\",\"contract\":\"b1\",\"title\":\"Message: Type b\",\"message\":\"[b1] \"}")
.WithTag("2"));

1 个答案:

答案 0 :(得分:1)

关键是将通知ID设置为您要加入的所有邮件。如下所示:

mNotificationManager =
    (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// Sets an ID for the notification, so it can be updated
int notifyID = 1;
mNotifyBuilder = new NotificationCompat.Builder(this)
    .setContentTitle("New Message")
    .setContentText("You've received new messages.")
    .setSmallIcon(R.drawable.ic_notify_status)
numMessages = 0;
// Start of a loop that processes data and then notifies the user
...
mNotifyBuilder.setContentText(currentText)
    .setNumber(++numMessages);
// Because the ID remains unchanged, the existing notification is
// updated.
mNotificationManager.notify(
        notifyID,
        mNotifyBuilder.build());

...

在此链接中找到更多文档: http://developer.android.com/guide/topics/ui/notifiers/notifications.html#Updating