1

I have added small icon in push notification but still not showing. I am using android 10 emulator. My icon have fulfill requirement that using white color with no background and store in mipmap folder. I have tried some solution on previous same question on stackoverflow but still not working. this is my code

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
                context, CHANNEL_ID)
                .setSmallIcon(R.mipmap.ic_notification)
                .setContentTitle(contentTitle)
                .setContentText(contentText)
                .setContentIntent(pendingIntent)
                .setPriority(NotificationCompat.PRIORITY_DEFAULT)
                .setAutoCancel(true);

Push notification icon still showing like this enter image description here

I have tried add this code on android manifest but still not working too

<meta-data
    android:name="com.google.firebase.messaging.default_notification_icon"
    android:resource="@mipmap/ic_notification" />

my targetSDK is 29

Did you ever encounter same issues and solved ?

Fairuz Yassar
  • 129
  • 3
  • 11
  • Did you try using other images from `drawable` folder? – Sam Chen Dec 30 '20 at 03:27
  • @SamChen i have tried but not working too – Fairuz Yassar Dec 30 '20 at 03:50
  • @FairuzYassar I would also reccomend you to try loading an image from the `drawable` folder. What I always do is, get an .svg icon first, import it in the `drawable` folder as a vector asset, the result of this step would be a generated .xml layout file. Finally call this layout file `.setSmallIcon(R.drawable.ic_yourIcon)` in the `NotificationCompat.Builder` like this and it will work. – BWappsAndmore Dec 30 '20 at 09:23
  • @BWappsandmore I have tried your solution but notification icon still showing grey square like above picture – Fairuz Yassar Jan 04 '21 at 03:03
  • 1
    @Fairuz Yassar search the Internet for a free `.svg` icon. Download it. In Android Studio right click on your `drawable` folder and then choose `New -> Vector Asset`. Choose Local file (SVG, PSD) as Asset Type. Select the icon that you downloaded. As soon the `.xml` layout file has been generated from it, click on it to edit. Edit `android:height="24dp"` and `android:width="24dp"` or play around with the size, 36dp, or 48dp. You will see the preview from the icon on the left side of the editor. Attach this file to your Notification. – BWappsAndmore Jan 04 '21 at 10:32

1 Answers1

0

Action Bar Icons require a file size of 24×24 pixels at the baseline size (MDPI). However, the image itself must be no more than 22×22 pixels centered within the Icon file.

The Icon Design must be single color white, #ffffff.

MDPI - 24 x 24  (drawable-mdpi)
HDPI - 36 x 36  (drawable-hdpi)
XHDPI - 48 x 48  (drawable-xhdpi)
XXHDPI - 72 x 72  (drawable-xxhdpi)
XXXHDPI - 96 x 96  (drawable-xxxhdpi)

For more details look Android Cheatsheet and Official Android documentation.

flederwiesel
  • 447
  • 1
  • 9
  • 17
  • I have all of this size and icon design has follow the rule but icon still not showing. i created icon using this tools https://romannurik.github.io/AndroidAssetStudio/icons-notification.html#source.type=clipart&source.clipart=ac_unit&source.space.trim=1&source.space.pad=0&name=ic_stat_ac_unit – Fairuz Yassar Jan 04 '21 at 02:50
  • Use Drawable Folder For data Message => .setSmallIcon(R.drawable.ic_notification) For Notification Message => android:resource="@drawable/ic_notification" – Abdul Haseeb Jan 04 '21 at 07:00