In my Android Application , I want to display App icon badges for all devices. From Oreo Version, it is an default feature. So that we can simply use notificationChannel.setShowBadge(true);
It is working fine for Oreo devices. but I want to show badges in below oreo devices too.
Code for reference
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
String CHANNEL_ID = "1";
NotificationChannel notificationChannel = new NotificationChannel(CHANNEL_ID, "Notification", NotificationManager.IMPORTANCE_HIGH);
notificationChannel.setShowBadge(true);
Bitmap icon = BitmapFactory.decodeResource(getApplicationContext().getResources(), R.mipmap.app_icon_launcher_main);
Notification notification = new Notification.Builder(getApplicationContext())
.setContentTitle(remoteMessage.getNotification().getTitle())
.setContentText(notificationMsg)
.setSmallIcon(R.mipmap.app_icon_launcher_main)
.setChannelId(CHANNEL_ID)
.setLargeIcon(icon)
.setAutoCancel(true)
.setContentIntent(pendingIntent)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setBadgeIconType(NotificationCompat.BADGE_ICON_SMALL)
.setStyle(new Notification.BigTextStyle().bigText(notificationMsg))
.build();
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.createNotificationChannel(notificationChannel);
notificationManager.notify(Integer.parseInt(data.get(stringConstants.NOTIFICATION_ID)), notification);
} else {
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setContentTitle(remoteMessage.getNotification().getTitle())
.setContentText(notificationMsg)
.setLargeIcon(BitmapFactory.decodeResource(getApplicationContext().getResources(), R.mipmap.app_icon_launcher_main))
.setSmallIcon(R.mipmap.app_icon_launcher_main)
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION), Notification.STREAM_DEFAULT)
.setAutoCancel(true)
.setContentIntent(pendingIntent)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setBadgeIconType(NotificationCompat.BADGE_ICON_SMALL)
.setStyle(new NotificationCompat.BigTextStyle().bigText(notificationMsg));
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(Integer.parseInt(data.get(stringConstants.NOTIFICATION_ID)), notificationBuilder.build());
}
}
How can I show badges for below Oreo Devices? Anybody faced this problem?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…