Android Oreo is not showing the notification icon correctly in the status bar and on the notification itself when app is closed fully(killed).It works fine when the app is open in the foreground.
int notificationId = new Random().nextInt(60000);
PendingIntent contentIntent = PendingIntent.getActivity(ctx, notificationId + 1,
intent, PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
setupChannels();
}
String CHANNEL_ID = getString(R.string.default_notification_channel_id);
Bitmap bitmap = null;
if (imageUrl != null && !imageUrl.equalsIgnoreCase("")) {
bitmap = getBitmapfromUrl(imageUrl);
}
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(ctx, CHANNEL_ID)
.setContentTitle(notificationTitle)
.setStyle(new NotificationCompat.BigPictureStyle()
.setSummaryText(notificationMsg)
.bigPicture(bitmap))/*Notification with Image*/
.setSound(defaultSoundUri)
.setContentText(msg)
.setChannelId(CHANNEL_ID)
.setAutoCancel(true)
.setContentIntent(contentIntent)
.setPriority(Notification.PRIORITY_HIGH);
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mBuilder.setColor(getResources().getColor(R.color.colorPrimaryDark));
}
mBuilder.setLargeIcon(BitmapFactory.decodeResource(ctx.getResources(), getNotificationIcon()));
mBuilder.setSmallIcon(getNotificationIcon());
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
mBuilder.getNotification().flags |= Notification.FLAG_AUTO_CANCEL;
private int getNotificationIcon() {
boolean useWhiteIcon = (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.O);
return useWhiteIcon ? R.mipmap.ic_launcher_icon_round : R.mipmap.ic_launcher;
}
Thanks in Advance...