2014-10-11 104 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