Can I override the default notification icon in android from application icon to user icon?

Can I override the default notification icon in android from an application icon to a custom icon?

I use the default firebase implementation to display notifications in the system tray when a push notification arrives. Since the icon of my application is colored and has a gradient, therefore, when a notification arrives, the android tries to make a black and white version and make it look like a white circle.

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

PS: we are waiting for solutions that require configuration changes in the manifest and do not want to use NotificationCompat.Builder

+8
android android-6.0-marshmallow android-manifest push-notification notifications
source share
6 answers

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 this helps people.

+16
source share

You can set

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

Small icon setSmallIcon ()

 NotificationCompat.Builder setLargeIcon (Bitmap icon) 

Set the large icon that appears in the ticker and notification.

in NotificationCompat.Builder.

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

+2
source share
 NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.custom_icon) .setContentTitle("FCM Message") .setContentText(messageBody) .setAutoCancel(true) .setSound(defaultSoundUri) .setContentIntent(pendingIntent); 
0
source share

You can do the following:

 int icon=R.drwable.icon; //Add your icon name here NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setSmallIcon(icon); 
0
source share

Builder for Notification objects. Provides a convenient way to set various notification fields and generate content views using the platform notification layout template. Check out the 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 a notification icon.

Hooray! Happy coding

0
source share

Yes you can do it. If you want to avoid the white circle icon, you must make your icon transparent and add a background color to it . So the color you use appears through a transparent icon and makes the icon visible and colorful. please check setSmallIcon and setColor in the code example below. Check this document 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); 
0
source share

All Articles