我有一個服務器與一些數據,並在我的應用程序我想通過推送通知顯示此數據,所以問題是我沒有得到如何合作通知用我的通知在狀態欄中輸入號碼。在我的應用程序中,我的服務器收到的通知爲ArrayList
。對於每個通知,我應該使用一個「通知構建器」,其中我會把圖標,名稱,desc等通知字段,至少我應該爲他們每個人調用「NotificationManager.notify」,但我怎麼可以顯示例如,我在狀態欄中收到3條消息(一個圖標的指示符爲3,NOT 3圖標),並且不會乘以通知聲音,但在打開狀態欄時仍然顯示所有消息。如何發送乘法推送通知並顯示它們的數量
我的代碼:
public void sendNotifications(ArrayList<Message> messages){
int notifyID = 0;
mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
for(Message message:messages){
Intent notificationIntent = new Intent(getApplicationContext(), MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(),0, notificationIntent,
PendingIntent.FLAG_CANCEL_CURRENT);
Resources res = getApplicationContext().getResources();
Notification.Builder builder = new Notification.Builder(getApplicationContext());
builder.setContentIntent(contentIntent)
.setSmallIcon(R.drawable.ic_launcher)
.setLargeIcon(BitmapFactory.decodeResource(res, messages.media))
.setTicker("Got a new message")
.setWhen(System.currentTimeMillis())
.setAutoCancel(true)
.setContentTitle(message.titile)
.setContentText(message.text);
Notification notification = builder.getNotification();
mNotificationManager.notify(notifyID, notification);
notifyID++;
}
}
UPD
更多的瞭解什麼,我想我已經添加的圖像
-pic1當我發送通知 - 圖標顯示我多少錢我得到了
-pic2當我打開一個狀態欄,它顯示了我所有的通知
這是可能做到這一點?
所以基本上你想要一個通知? –
是的,但是如果我發送1條通知我如何顯示3條消息的內容?我需要像通知堆棧或通知列表,它會在狀態欄中顯示1個圖標,但當我打開狀態欄時,仍然會顯示所有通知。 – whizzzkey
因此,Vang在他的回答中提出了建議,您可以看到gmail示例在這方面做了同樣的事情。 http://developer.android.com/guide/topics/ui/notifiers/notifications.html –