根据https://developer.android.com/training/notify-user/badges 从 Android 8 开始,操作系统允许设置应用程序图标通知徽章,但我无法让它工作。
NotificationManagerCompat nm = NotificationManagerCompat.from(activityContext);
if (Build.VERSION.SDK_INT >= 26) {
NotificationChannel nc = new NotificationChannel("ab", "chanelName", NotificationManager.IMPORTANCE_DEFAULT);
nc.setDescription("A chanel description here");
nc.setShowBadge(true);
NotificationManager nmm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nmm.createNotificationChannel(nc);
}
NotificationCompat.Builder nb = new NotificationCompat.Builder(App.instance, "ab");
nb.setSmallIcon(R.drawable.accept_icon);
nb.setTicker("here is the ticker");
nb.setContentText("Here content text");
nb.setContentTitle("Here content title");
nb.setNumber(5);
nb.setBadgeIconType(NotificationCompat.BADGE_ICON_SMALL);
nm.notify(1, nb.build());
我正在使用 Nexus 6P 和 android 8.1 。它在系统栏中显示通知,但不在应用程序图标上显示徽章。我错过了什么?
相关分类