简体   繁体   中英

notification bar + push notification clarifications

In my app I am applying push notifications and making them using the notificationCompat class.

I am assigning each notification a unique ID therefore, each one is visible seperately in the notification bar.

When the user clicks on a notification, using a pending intent, I am directing the user towards a certain activity, where he can see all the previous notifications. ( I read them from mysql db ).

question 1 : I want all the notifications in the status bar get cleared if the user clicks only on one of them. Can be a any random one (given it is from my app). the setAutoCancel() method, only removes the one pressed, and I cant seem to know where I would implement the cancelAll() method.

Answer :

@Override
protected void onResume()
{
    super.onResume();
    NotificationManager notificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.cancelAll();
}

question 2 : Since each notification has unique ID, sending several notifications from an individual app, and in case of not checking from the user, might result in several icons to appear in the notification bar. Android, starts collecting them and showing badge numbers on them once they start taking too much space and the system realizes there is no enough space for them. Is there any method to combine them all from the beginning ? That is, whenever I send a notification, and it is not checked, the second one should be added and a single icon should appear on the bar with the number 2 or + , whatever the system uses.

I'd like to combine question 1 and 2 into a single answer: Do not show multiple notifications! Show one notification and update it when you have more than one unchecked notification. As a user I would get really annoyed if my notification bar was spammed with notifications from a single app. Think of the GMail app and it's notifications if you would get one per incoming e-mail.

On pre 4.1 devices you'll have to make do with the Normal View . If you have only one unchecked message you could show the contents of the message immediately in the notification, and if you have more than one you could do something like the GMail notification and show something like "5 unchecked messages".

On 4.1+ devices you can use the Big View to show all of them at once.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM