2010-06-15 38 views
2

我已經能夠在Android模擬器上成功顯示通知號碼計數。但是,當我在實際的Android手機上使用它時,它不會顯示任何內容。關於爲什麼可能有區別的任何建議?Android通知欄號碼

+0

什麼是通知數算? – Macarse 2010-06-15 02:54:40

+0

http://developer.android.com/reference/android/app/Notification.html#number – JonF 2010-06-15 03:01:53

+0

特別是哪款手機?我認爲有些人實際上忽略了這個功能。 – 2010-12-27 02:41:10

回答

2

在我的情況下,這是手機的東西。這是一個令人難以置信的Droid。它不適用於android 2.1,但Verizon的2.2發佈解決了這個問題。

+0

您能否提供您使用的代碼? – h4ck3d 2012-03-11 22:45:44

3

先嚐試用數字1設置它,然後再往上走。從這裏建議:http://developer.android.com/guide/topics/ui/notifiers/notifications.html

數場

該值指示由通知表示事件的當前數量。相應的編號覆蓋在狀態欄圖標的頂部。如果您打算使用此字段,則必須在首次創建通知時以「1」開頭。 (如果您在更新過程中從零值更改爲任何東西時,不顯示的數字。)

+0

好!它適用於Android 2.1。 – 2011-08-31 13:58:47

1

(爲後人)

要闡述什麼Izkata說,如果你提出了一個通知,沒有「號碼」計數,然後您想要添加號碼,您需要取消現有通知並重新設置號碼字段集。 (「取消」是NotificationManager方法之一。)從0到數字不會顯示數字,除非您取消原始通知。

同樣,如果你有一個通知上的數字,並希望回到一個空白的通知,你需要取消當前一個,並重新沒有數字。從數字到0將只顯示沒有任何內容的小綠色泡泡。

請注意,如果您只想更改現有號碼,則可以使用新號碼重新發出通知 - 無需取消前一號碼。

+0

我已經設置了一個通知,它使用'builder.setContentText(「Resumed」)更新。setNumber(7); notificationManger.notify(1,builder.build());'。我在通知抽屜中看到「已恢復」文本和數字「7」,但該號碼未顯示在通知欄圖標上。任何想法爲什麼? – 2015-03-18 21:59:38

+0

其實,這個數字出現在一個氰基模式的平板電腦中,但不是在三星筆記4中,儘管兩者都使用了android 4.4.4。 – 2015-04-10 13:07:41

1
 Take two global variable count, i; 
     public void createNotification(View view){ 



NotificationManager mNotificationManager=(NotificationManager)getSystemService(NOTIFICATION_SERVICE); 
Notification notification = new Notification(R.drawable.logo, 
     "A new notification", System.currentTimeMillis()); 
// Hide the notification after its selected 
notification.flags |= Notification.FLAG_AUTO_CANCEL; 
Intent intent = new Intent(this,SampleJsonReadingActivity.class); 
PendingIntent activity = PendingIntent.getActivity(this, 0, intent, 0); 
notification.setLatestEventInfo(this, "This is the title", 
     "This is the text", activity); 
if(count==1){ 
    count ++; 
} 
    else{ 
     i++; 

    } 
notification.number +=i; 
mNotificationManager.notify(0, notification); 

}

它爲我....