I'm testing the stackable notifications (Stacking Notifications article).
I detected that in some cases the notifications are not shown after the notify()
call in devices running android 4.X KitKat.
To simply the problem I created this code that simulates a notification (button1) and a second notification with a summary (button2)
private final static int NOTIFICATION_ID_A=6;
private final static int NOTIFICATION_ID_B = 7;
private final static int NOTIFICATION_ID_SUMMARY = 8;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showNotif(NOTIFICATION_ID_A,false);
}
});
findViewById(R.id.button2).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showNotif(NOTIFICATION_ID_B,false);
showNotif(NOTIFICATION_ID_SUMMARY,true);
}
});
}
private void showNotif(int notificationId,boolean groupSummary) {
CharSequence title="Title "+notificationId;
CharSequence message="Message "+notificationId;
NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(this);
notifBuilder.setSmallIcon(R.drawable.icon_notifications);
notifBuilder.setContentTitle(title);
notifBuilder.setContentText(message);
notifBuilder.setGroupSummary(groupSummary);
notifBuilder.setContentIntent(PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT));
notifBuilder.setGroup("group_" + 1);
NotificationManagerCompat.from(this).notify(notificationId, notifBuilder.build());
}
The idea is first to press the button1 and then the button2. It works great in android 5.0+ showing the first notif first and the summary when the second button is clicked, but in Android 4.X the button1 does not show anything.
Where is the error?
Thanks