Problem with notification icon

3

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.

    
asked by anonymous 27.11.2018 / 18:23

2 answers

2

After the test, changing the

  

.setContentText (message)

by

  

.setContentText ("Passed by my function")

of the function that should be called

It was found that firebase was treating push when the application was in background and therefore the image was not appearing.

Knowing this we have two options:

  • You can send the icon by setting push . The problem in this case is that if it is essential that push pass through the function, this solution will not resolve.

  • Make push so that firebase always goes through the function. Unfortunately I never did this but maybe this link helps you link

29.11.2018 / 22:10
1

Perform the following Test:

{
  "to": "MYDEVICETOKEN",
  "notification": {
    "body": "Test from postman",
    "icon": "ic_notification"
  }
}
    
29.11.2018 / 21:13