5
I’m creating a push notification system with firebase in my project.
The code that generates the push is like this:
notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_notification)
.setColor(getResources().getColor(R.color.colorPrimary))
.setContentTitle(getResources().getString(R.string.app_name))
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
Everything works perfectly, icone, message, background color, however, only until Android Lollipop (5.0), from there is only a white circle without loading the image and without the background color.
After a lot of research, I found answers like these:
https://stackoverflow.com/questions/28387602/notification-bar-icon-turns-white-in-android-5-lollipop
https://blog.clevertap.com/fixing-notification-icon-for-android-lollipop-and-above/
But none of them really helped me, one of the answers says to do a validation of the SDK, like this:
private int getNotificationIcon() {
boolean useWhiteIcon = (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP);
return useWhiteIcon ? R.drawable.icon_silhouette : R.drawable.ic_launcher;
}
But it doesn’t say anything about sizes, about what I need to do to make it work above the Lollipop SDK.
Someone can give me a light?
Link 3 gives the answer.
– ramaral
Strange, from what I understand he says to do the png white color with hollow background only, but I’ve always made all the notification icons like this, and it doesn’t work for anything from 5.0.1 on.
– Leonardo Dias
I have never tested in 5+, but what I understand is that anything that is not transparent is put in white. Read the note on Androidassetstudio under the word "source"
– ramaral