我有一个服务器与一些数据,并在我的应用程序我想通过推送通知显示此数据,所以问题是我没有得到如何合作通知用我的通知在状态栏中输入号码。在我的应用程序中,我的服务器收到的通知为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 –