I have a problem that I can't find the answer to. I have tried the AndroidDeveloper tutorials, I have searched here on stackoverflow and on google but either my search-skills are awefull or there's no answer I think answers my problem.
I want to stack message notifications into one notification for all new messages when there are more than one. I can make a notification appear for each message but I cannot make a stack/summary notification.
The best I get is this : http://developer.android.com/images/android-5.0/notifications/Summarise_Dont.png
What I want is this : http://developer.android.com/images/android-5.0/notifications/Summarise_Do.png
I am using API 19 and it does not have to be back-compatible. Writign my code in AndroidStudio and testing in Genymotion.
I have tried using NotificationCompatManager with the result of having multiple notifications: NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
I have also tried using NotificationManager with the same result, that is multiple notifications:
NotificationManager notificationManager=(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
My notification looks like this:
Notification notification = new NotificationCompat.Builder(this)
.setContentTitle( "New message from... ")
.setContentText("Message:...")
.setSmallIcon(R.drawable.icon)
.setContentIntent(pIntent)
.setSound(RingtoneManager.getDefaultUri(TYPE_NOTIFICATION))
.setGroup(mNoti)
.setGroupSummary(true)
.setAutoCancel(true)
.build();
And I fire the notification like this:
notificationManager.notify(counter, notification);
Where counter increments for each notification so each notification has its own ID.
I have also tried this form for building and fiering the notification without succsess:
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.icon)
.setContentTitle("message from...")
.setContentText("message...")
.setContentIntent(pIntent)
.setAutoCancel(true)
.setGroup(mNoti)
.setGroupSummary(true)
.setSound(RingtoneManager.getDefaultUri(TYPE_NOTIFICATION));
notificationManager.notify(counter, notificationBuilder.build());
setGroup obviously does noting for me. I don't understand why it doesn't work or how I'm supposed to make it work.
my group look like this:
final static String mNoti = "mNoti";
The only thing that comes remotely close to what I want is using the same ID for all notifications so that the new notifications overrides the old ones, and using setNumber(int) while building the notification. However this doesn't truely give me the result I want because I don't think I can get the number of notifications not handled by the user. Or can I?
Can anyone help me arrive at my desired goal?