With Android O developer preview google has introduced notification badges that are supposed to be shown on launcher icon. I am using emulator with Android O from dev channel.I wrote a simple code to show notification badge but it does not seem to work -
Notification notification = new Notification.Builder(getApplicationContext())
.chooseBadgeIcon(Notification.BADGE_ICON_SMALL)
.setSmallIcon(android.R.drawable.btn_star)
.setNumber(10)
.build();
mNotificationManager.notify(1, notification);
It just shows as normal notification.
API - https://developer.android.com/reference/android/app/Notification.Builder.html#chooseBadgeIcon(int)
Has anyone worked on this yet? Am I missing something?
Show badge is enabled in settings.
Tried with NotificationChannel too. Does not work -
NotificationChannel mChannel = new NotificationChannel("TestBadge_id", "TestBadgeName", NotificationManager.IMPORTANCE_HIGH);
mChannel.enableLights(true);
mChannel.setLightColor(Color.RED);
mChannel.setShowBadge(true);
mNotificationManager.createNotificationChannel(mChannel);
Notification notification = new Notification.Builder(getApplicationContext())
.chooseBadgeIcon(Notification.BADGE_ICON_SMALL)
.setSmallIcon(android.R.drawable.btn_star)
.setNumber(10)
.setChannel("TestBadge_id")
.build();
mNotificationManager.notify(1, notification);