如何发送乘法推通知,并告诉他们的数 [英] How to send multiply push-notifications and show number of them
问题描述
我有一些数据的服务器,并在我的应用我想说明通过推送通知这个数据,所以这个问题是我没有得到如何合作与我notifiсations状态栏通知号码。在我的应用程序,我得到的通知是的ArrayList
从我的服务器。对于每个通知我应该使用通知建设者,在其中我把通知状图标,名称,说明等领域,至少我应该叫NotificationManager.notify为他们每个人,但我怎么能证明我刚刚得到了例如3消息在我的状态栏(与3指示灯,不是3图标中的一个图标),但不会乘以一个通知声音,但仍显示出所有的人,当我打开状态栏。
I have a server with some data and in my app I want to show this data via push-notification, so the problem is I didn't get how to cooperate notification number in status bar with my notifiсations. In my app I get notifications as ArrayList
from my server. For each notification I should use a "Notification builder", in which I'll put notify fields like icon, name, desc etc, and at least I should call "NotificationManager.notify" for each of them, but how I can show that I've just gotten 3 messages for example in my status bar(one icon with indicator of 3, NOT 3 icons), and don't multiply a notification sound, but still show all of them when I open a status bar.
我的code
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
有关更多的了解我想要什么,我已经添加了图像
UPD
For more understanding what i want to i've added an images
-pic1当我发送通知 - 图标显示我我有多少钱
-pic1 When i send notifications - icon shows me how much i got
-pic2当我打开一个状态栏,它显示我所有的通知
-pic2 When i opened a status bar it shows me all my notifies
这是可能做到这一点?
推荐答案
您不能这样做 - 合并3通知到一个
You cannot do that - Combine 3 notification into one.
要么你创建一个单一的通知结合所有的通知或这样才。
Either you create a single notification combining all the notifications or like this only.
这是没有必要,你会得到3通知。你可以得到1或2个也。
It is not necessary that you will get 3 notifications. You can get 1 or 2 also.
我没有看到这里的问题。如果有3个通知,你会看到在状态栏中的图标3
I don't see the issue here. If there are 3 notifications, you will see 3 icons in the status bar.
每个图标重新presents在下拉通知条目酒吧,有一个图标重新present多个条目就没有真正意义。
Each icon represents an entry in the pull down notification bar- having one icon represent multiple entries wouldn't really make sense.
这篇关于如何发送乘法推通知,并告诉他们的数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!