Android Color Notification Icon
I found the answer to my question here: https://stackoverflow.com/a/44950197/4394594
I don't know entirely what the problem was, but by putting the huge png that I was using for the icon into the this tool https://romannurik.github.io/AndroidAssetStudio/icons-notification.html#source.type=image&source.space.trim=1&source.space.pad=0&name=ic_skylight_notification
and by placing the generated icons it gave into my mipmap folder, I was able to get the setColor(...)
property to work correctly.
For firebase nofitications sent from console you just need to add this in your manifest:
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/white_logo" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="@color/custom_color" />
Where white_logo is your app white logo, and custom_color is the color you want to have the icon and text colored.
More details here: https://firebase.google.com/docs/cloud-messaging/android/client
Here is what I did for my app ...
private void showNotification(Context context) {
Log.d(MainActivity.APP_TAG, "Displaying Notification");
Intent activityIntent = new Intent(context, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, activityIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);
mBuilder.setSmallIcon(R.drawable.ic_notification);
mBuilder.setColor(Color.GREEN);
mBuilder.setContentIntent(pendingIntent);
mBuilder.setContentTitle("EarthQuakeAlert");
mBuilder.setContentText("It's been a while you have checked out earthquake data!");
mBuilder.setDefaults(Notification.DEFAULT_SOUND);
mBuilder.setAutoCancel(true);
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(1, mBuilder.build());
}
Sample With Color:
Sample without Color:
When building the notification, you can set the color and the icon. If your icon is a pure white image, it'll apply the color for you in the correct spots.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val manager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
val notificationId = 10 // Some unique id.
// Creating a channel - required for O's notifications.
val channel = NotificationChannel("my_channel_01",
"Channel human readable title",
NotificationManager.IMPORTANCE_DEFAULT)
manager.createNotificationChannel(channel)
// Building the notification.
val builder = Notification.Builder(context, channel.id)
builder.setContentTitle("Warning!")
builder.setContentText("This is a bad notification!")
builder.setSmallIcon(R.drawable.skull)
builder.setColor(ContextCompat.getColor(context, R.color.colorPrimary))
builder.setChannelId(channel.id)
// Posting the notification.
manager.notify(notificationId, builder.build())
}