我刚刚注意到,当我创建通知时,其他手机上的应用图标上没有通知徽章,只有版本4.4及以下通知栏中的通知。
我想在各种Android版本的app图标上显示红色通知徽章,就像下面的截图一样:
以下是我用于显示通知的代码,基本上用户会在通知栏上收到通知,但不会在应用中收到红色徽章编号:
private void sendNotification(NotificationVM source) {
Intent intent = new Intent(this, NotificationActivity.class);
intent.putExtra(IntentPutNameConstant.NotificationActivity.NOTIFICATION_ID, source.getNotificationId());
intent.putExtra(IntentPutNameConstant.NotificationActivity.NOTIFICATION_TYPE, source.getNotificationType());
intent.putExtra(IntentPutNameConstant.NotificationActivity.USER_FROM_USERNAME, source.getUserFrom().getUsername());
intent.putExtra(IntentPutNameConstant.NotificationActivity.MESSAGE, source.getMessage());
intent.putExtra(IntentPutNameConstant.NotificationActivity.SOURCE_ID, source.getSourceId());
intent.putExtra(IntentPutNameConstant.NotificationActivity.EXTERNAL_URL, source.getExternalUrl());
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_app_launcher_72)
.setContentTitle("Investagrams")
.setContentText(source.getMessage())
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
//Vibration
notificationBuilder.setVibrate(new long[] { 0, 200, 200, 200, 200, 200 });
//LED
//notificationBuilder.setLights(Color.RED, 3000, 3000);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Notification notif = notificationBuilder.build();
notif.flags |= Notification.FLAG_AUTO_CANCEL;
/*notif.ledARGB = 0xFFff0000;
notif.flags = Notification.FLAG_SHOW_LIGHTS;
notif.ledOnMS = 100;
notif.ledOffMS = 100;*/
notificationManager.notify((int)source.getNotificationId() /* ID of notification */, notif);
}
答案 0 :(得分:0)
这是设备制造商特定的。具有此功能的设备会自动执行此操作。它计算当时显示的通知总数并显示该数字。