3
I know there are several questions related to this. However, I have found nothing with my specific case. I will explain...
I use the same code to display a notification both for notifications when the app is in the foreground and for in the background. Behold:
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 the image presents error:
I don’t believe the mistake is in the picture, but I could be wrong. I researched the standard android for versions prior to Lollipop and I believe I am acting in the correct way... Mas... I may be wrong again. What would be strange, because android would present the image one way and another not?
Does anyone suggest anything? If you need more information I am available.
Remarks
1 - Even if I create an Asset vector in xml with android studio the result is exactly the same.
2 - I did tests on several different emulators and the result is the same.
It may be that it is not going through this function when in the background and using the firebase standard, do the following test replace the
.setContentText(message)
for.setContentText("Passou por minha função")
, push with a different message and see what happens– Icaro Martins
@Icaromartins will check. 1 minute.
– Andrei Coelho
@Icaromartins the problem is exactly this.
– Andrei Coelho
@Icaromartins I would never imagine... XD .. The message was always displayed!
– Andrei Coelho
@Icaromartins thanks man! I wanted to make you win these two little... =)
– Andrei Coelho
Now you have two options: 1) you can send the icon by push setting as shown in the answer below. the problem is that it will not arrive in its function. 2) Push in such a way that firebase always calls a function of yours, unfortunately I never did this but maybe this link will help you https://stackoverflow.com/a/37845174/2456894
– Icaro Martins