I want to stack notifications using setGroup (as described here: https://developer.android.com/training/wearables/notifications/stacks.html)
Basically, I use 0 as notification id (always the same) and builder.setGroup("test_group_key")
but a new notification always replaces the previous one.
What could be the problem ?
Code:
public BasicNotifier(Context context) {
super(context);
notifManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mBuilder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_launcher)
.setSound(alarmSound)
.setAutoCancel(true);
stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addParentStack(getParentActivityClass());
}
public void showNotification(String title, String text, Intent intent, Class cls) {
if (text.length() > 190)
text = text.substring(0, 189) + "...";
mBuilder.setTicker(text).setContentText(text).setContentTitle(title);
Intent notificationIntent = intent == null ? new Intent() : new Intent(intent);
notificationIntent.setClass(getContext(), cls);
stackBuilder.addNextIntent(notificationIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(resultPendingIntent);
mBuilder.setGroup("test_group_key");
Notification notif = mBuilder.build();
notif.flags |= Notification.FLAG_AUTO_CANCEL;
notifManager.notify(replaceOnNew ? 0 : nextId++, notif); // replaceOnNew
// is "true"
Log.i(TAG, "Notification shown: " + nextId + " = " + title);
}
EDIT:
It seams there is a problem when using NotificationManagerCompat, the notifications are not being displayed at all.
NotificationManagerCompat notificationManager =
NotificationManagerCompat.from(getContext());
notificationManager.notify(id, notif);