2014-02-10 105 views
1

我期待在this code in the Android documentation堆疊通知:如何實現堆疊通知

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()); 
... 

,但我不明白你如何保持跨越多個收據從GCM軌道numMessages參數或如何開始正如他們在評論中所說的那樣,一個「處理數據的循環」。我想你會需要檢索任何當前通知,然後將新數據附加到它們。任何幫助讚賞。

編輯:我也不明白,如果每個通知都覆蓋最後一個,爲什麼不直接發送一個通知給最後一次迭代呢?

+0

您是否解決了您的問題?如果是這樣,怎麼樣?我想知道同樣的事情。 –

回答

0

試試:

new Notification.Builder().setAutoCancel(false).setOngoing(false); 

好路!當用戶點擊

+0

這隻會讓通知持續存在,但我仍然不知道如何處理多個GCM RECEIVE意圖。 – ashishduh

+0

請閱讀:http://developer.android.com/google/gcm/index.html祝您好運! –

0

mBuilder.setAutoCancel(true); //自動取消它 mBuilder.setOngoing(true);/*如果爲真: 正在進行的通知,從常規的通知不同,在以下幾個方面:

正在進行的通知上面的通知面板的常規通知排序。 正在進行的通知沒有「X」關閉按鈕,並且不受「全部清除」按鈕的影響。 */