25

Can I override default push notification icon in android from app icon to custom icon?

I am using default firebase implementation to display notification in system tray, when a push notification come. Since my app icon is coloured and has gradient, so when a notification comes, android tried to make a black/white version of it, and make it look like a white circle.

Is there a way to update the default notification icon to something else instead of default app icon?

PS: Looking forward for a solution which required a config change in manifest and don't want to use NotificationCompat.Builder

Shashank
  • 834
  • 1
  • 9
  • 13

7 Answers7

36

you can use this in your manifest according to https://firebase.google.com/docs/cloud-messaging/android/receive

    <!-- Set custom default icon. This is used when no icon is set for incoming notification
    messages.See README(https://github.com/firebase/quickstart-android/tree/master/messaging#custom-default-icon) for more. -->
    <meta-data
        android:name="com.google.firebase.messaging.default_notification_icon"
        android:resource="@drawable/ic_stat_ic_notification" />

    <!-- Set color used with incoming notification messages.
    This is used when no color is set for the incoming notification message. See README
    (https://github.com/firebase/quickstart-android/tree/master/messaging#custom-default-color) for more. -->
    <meta-data
        android:name="com.google.firebase.messaging.default_notification_color"
        android:resource="@color/colorAccent" />

Hope it helps people.

elsennov
  • 875
  • 9
  • 14
3

You can set

  .setSmallIcon(int);
  .setLargeIcon(bitmap);

A small icon, set by setSmallIcon()

NotificationCompat.Builder setLargeIcon (Bitmap icon)

Set the large icon that is shown in the ticker and notification.

in NotificationCompat.Builder.

Documentation - https://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html

kalpana c
  • 2,739
  • 3
  • 27
  • 47
0
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.mipmap.custom_icon)
                .setContentTitle("FCM Message")
                .setContentText(messageBody)
                .setAutoCancel(true)
                .setSound(defaultSoundUri)
                .setContentIntent(pendingIntent);
Muhammad Younas
  • 1,543
  • 1
  • 22
  • 32
0

You can do like this:

int icon=R.drwable.icon; //Add your icon name here
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setSmallIcon(icon);
Dhruv
  • 1,801
  • 1
  • 15
  • 27
  • Is there a way it can be done without Notification.Builder. Like the default icon is picked up from manifest which is equal to app icon. Can it be done at config level so that it applied for all notifications. – Shashank Jun 09 '16 at 13:46
  • Do you want to generate custom notification? – Dhruv Jun 10 '16 at 03:27
  • He is using default Firebase notifications, so he has no access to Notification Builder. – EdgarK Aug 12 '16 at 15:18
0

Builder class for Notification objects. Provides a convenient way to set the various fields of a Notification and generate content views using the platform's notification layout template. Check Official Documentation here

 Notification noti = new Notification.Builder(mContext)
     .setContentTitle("New mail from " + sender.toString())
     .setContentText(subject)
     .setSmallIcon(R.drawable.new_mail)
     .setLargeIcon(aBitmap)
     .build();

Here you can set custom fields including Icon for your notifications.

Cheers! Happy Coding

Salman Nazir
  • 2,759
  • 2
  • 28
  • 42
0

Yes you can do it.If you want to avoid white circle icon you must make your icon transparent and add background color to it.So the color you use appears out through the transparent icon and makes the icon visible and colorful. please check for setSmallIcon and setColor in the below sample code.Check this doc and search for transparent

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
                context)
                .setContentIntent(contentIntent)
                .setSmallIcon(R.drawable.transaparentIcon)
                .setColor(context.getResources().getColor(R.color.notif_color))
                .setWhen(System.currentTimeMillis())
                .setContentTitle(context.getString(R.string.app_name))
                .setStyle(
                        new NotificationCompat.BigTextStyle()
                                .bigText(notificationText))
                .setContentText(notificationText)
                .setAutoCancel(true);
Anup Dasari
  • 488
  • 1
  • 4
  • 13
0

What worked for me is:

Changing the icon-tag in the manifest file

        android:icon="@drawable/ic_icon"

(I'm using AndroidX Media3)

max
  • 71
  • 5