2014-10-11 101 views
0

我的问题是如何合并多个通知? 这里是我的代码:如何合并多个推送通知?

private void sendNotification(String msg) { 
    mNotificationManager = (NotificationManager) this 
      .getSystemService(Context.NOTIFICATION_SERVICE); 

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, 
      new Intent(this, DemoActivity.class), 0); 

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
      this) 
      .setSmallIcon(R.drawable.ic_stat_gcm) 
      .setContentTitle("GCM Notification") 
      .setStyle(new NotificationCompat.BigTextStyle().bigText(result)) 
      .setContentText(result); 

    mBuilder.setContentIntent(contentIntent); 
    mNotificationManager.notify(++NOTIFICATION_ID, mBuilder.build()); 
} 

它给了我喜欢的Windows Phone每一个人的通知,但我不能合并成一个通知。所以,请给我建议在这个方法中实现什么。

+0

mNotificationManager.notify(NOTIFICATION_ID,mBuilder.build()); ...试试这个.. – 2014-10-11 07:41:13

+0

Thnks for this ... but it overwrite the message but I want like .....“2 message” – 2014-10-11 08:05:42

+0

Do你的意思就像在whatsapp?即来自用户的2条消息? – berserk 2014-10-11 08:51:47

回答

1

您不能简单地添加多个通知。当你收到通知时,你只需要做一些合乎逻辑的工作。假设您正在制作聊天应用程序。你会收到一条消息的通知。现在,当您收到其他消息的通知时,请检查是否有未决未读消息。如果是这样,请将通知文本更改为“x新消息”。

+0

如何“检查是否有未决的未读消息。” – kAmol 2015-09-16 07:40:28