I'm using Firebase Notification for my app's push notifications. All working well but notification icon shows white circle when app is not running. I'm targeting SDK version 23, also I'm using Roman Nurik's notification icon generator to generate white-on-transparent icons.
Notification icon is showing correctly when app is on foreground and running. img
But icon gets replaced with generic white circle when app is in background or killed. img
Here's my notification builder method:
private void sendNotification(String messageTitle, String messageBody) {
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder notification = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_stat_notification_icon)
.setContentTitle(messageTitle)
.setContentText(messageBody)
.setStyle(new NotificationCompat.BigTextStyle().bigText(messageBody))
.setAutoCancel(true)
.setPriority(Notification.PRIORITY_DEFAULT)
.setDefaults(Notification.DEFAULT_ALL)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notification.build());
}
I've already found an answer on similar issue: Notification Icon with the new Firebase Cloud Messaging system
Unfortunately this is a limitation of Firebase Notifications in SDK 9.0.0. When the app is in the background the launcher icon is use from the manifest (with the requisite Android tinting) for messages sent from the console.
If the app is in the foreground (or a data message is sent) you should be able to use your own logic to customise, and you should be able to customise the icon if sending the message from the HTTP/XMPP APIs. Right now with messages sent from the console you'll get this behavior.
It seems to be that the best way to avoid this Firebase Notifications bug is to change your targetSdkVersion
in build.gradle
to 19. The notification icon will be then colored. Firebase after a while will fix this issue.
Hope it will help