How to set the app icon as the notification icon in the notification drawer

前端 未结 3 530
轮回少年
轮回少年 2020-12-01 07:51

As shown in the figure...
I am getting my notification icon(on left to the red colour).
But I need to display the app icon as shown by the black arrow

相关标签:
3条回答
  • 2020-12-01 08:19

    Try this code at your notification builder :

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
                    .setSmallIcon(R.mipmap.ic_launcher)
                    .setLargeIcon(BitmapFactory.decodeResource(context.getResources(),
                            R.mipmap.ic_launcher))
                    .setContentTitle(title)
                    .setContentText(message)
                    .setAutoCancel(true)
                    .setSound(defaultSoundUri)
                    .setContentIntent(pendingIntent);
    
    android.app.NotificationManager notificationManager =
                    (android.app.NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    
    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
    

    Set Large icon does the trick.Comment below if you have any further info

    0 讨论(0)
  • 2020-12-01 08:20

    Set this parameter while building notification

    setLargeIcon(BitmapFactory.decodeResource(context.getResources(),R.mipmap.ic_launcher))

    0 讨论(0)
  • 2020-12-01 08:24

    I know its bit late to answer here and also its already been answered, but I came here looking for an easy fix using firebase notifications. Someone like me visiting here can do the solution by recommended and easy way of firebase notification, which is simply adding meta-data in manifest.

    Reference

    <!-- Set custom default icon. This is used when no icon is set for incoming notification messages. -->
    <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. -->
    <meta-data
        android:name="com.google.firebase.messaging.default_notification_color"
        android:resource="@color/colorAccent" />
    
    0 讨论(0)
提交回复
热议问题