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

后端 未结 6 1763
鱼传尺愫
鱼传尺愫 2021-02-12 16:07

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,

相关标签:
6条回答
  • 2021-02-12 16:37
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                    .setSmallIcon(R.mipmap.custom_icon)
                    .setContentTitle("FCM Message")
                    .setContentText(messageBody)
                    .setAutoCancel(true)
                    .setSound(defaultSoundUri)
                    .setContentIntent(pendingIntent);
    
    0 讨论(0)
  • 2021-02-12 16:38

    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);
    
    0 讨论(0)
  • 2021-02-12 16:45

    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

    0 讨论(0)
  • 2021-02-12 16:49

    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

    0 讨论(0)
  • 2021-02-12 16:54

    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.

    0 讨论(0)
  • 2021-02-12 16:58

    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);
    
    0 讨论(0)
提交回复
热议问题