I know there are several questions related to this. However, I did not find anything with my specific case. I'll explain ...
I use the same code to display a notification for both notifications when the application is in the foreground and in the background. See:
final int icon = R.drawable.ic_stat_name; // aqui está a imagem
PendingIntent resultPendingIntent;
resultIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
resultPendingIntent =
PendingIntent.getActivity(
mContext,
0,
resultIntent,
PendingIntent.FLAG_CANCEL_CURRENT
);
final NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
mContext, CHANNEL_ID);
Notification notification;
NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
inboxStyle.addLine(message);
notification = mBuilder
.setSmallIcon(icon)
.setAutoCancel(true)
.setContentTitle(title)
.setContentIntent(resultPendingIntent)
.setStyle(inboxStyle)
.setContentText(message)
.setColor(ContextCompat.getColor(mContext, R.color.colorPrimary))
.build();
Log.i("Notificação -> ", "Foi gerada");
NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(NOTIFICATION_ID, notification);
And in both cases they show the notification successfully, but only when the application is in the background does the image display an error:
I do not believe the error is in the image, but I may be wrong. I've researched the android pattern for pre-lollipop versions and I believe I'm acting the right way ... But ... I may be wrong again. What would be strange, then why would the android present the image in one way and another not?
Does anyone suggest anything? If you need more information I will be at your disposal.
Notes
1 - Even if I create an asset vector in xml with android studio the result is exactly the same.
2 - I tested several different emulators and the result is the same.