在 Android O 开发者预览版中,谷歌引入了应该显示在启动器图标上的通知徽章。我正在使用来自开发频道的 Android O 模拟器。我编写了一个简单的代码来显示通知徽章,但它似乎不起作用 -
Notification notification = new Notification.Builder(getApplicationContext())
.chooseBadgeIcon(Notification.BADGE_ICON_SMALL)
.setSmallIcon(android.R.drawable.btn_star)
.setNumber(10)
.build();
mNotificationManager.notify(1, notification);
它只是显示为正常通知。
API - https://developer.android.com/reference/android/app/Notification.Builder.html#chooseBadgeIcon(int)
有没有人在这方面工作过?我错过了什么吗?
显示徽章在设置中启用。
也尝试过 NotificationChannel。不工作 -
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);