2

I create simple notification:

Notification.Builder builder = new Notification.Builder(this);
builder
    .setContentTitle("title")
    .setContentText("this is small text")
    .setSmallIcon(R.drawable.my_small_icon)
    .setTicker("test Ticker")
    .setStyle(new Notification.BigTextStyle().bigText("big mess"));
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {

    NotificationManager notificationManager = getSystemService(NotificationManager.class);
    Bitmap image = BitmapFactory.decodeResource(this.getResources(), R.drawable.icon);
    builder.setLargeIcon(image);
    RemoteViews contentView = builder.createContentView();
    RemoteViews bigContentView = builder.createBigContentView();

    // custom contentView and bigContentView

    builder.setCustomContentView(contentView);
    builder.setCustomBigContentView(bigContentView);
    Notification n = builder.build();
    builder.build();

    notificationManager.notify(1, n);
}

my_small_icon is an image white color in transparent, my problem is different this question

It shows my small icon in the status bar same my logo, but it shows a gray square enter image description here

This problem happening in Redmi 4A 7.1 LG K530F and Galaxy J7 display normally.

Can you give me the advice to fix it?

I use Android Asset Studio but it can't help.

hong4rc
  • 3,999
  • 4
  • 21
  • 40

2 Answers2

0

you can go your project res folder

res=>drawable folder=>right click in drawable folder => open popup => new => select image assets => open assest studio => select icon type => notification icon => and create and set that icon as a notification

Kukadiya Anil
  • 116
  • 2
  • 7
-1

First of all you will have to check that the image you are using for notification has a transparent background or not.

Secondly, you will have to maintain the size for every density

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)                             

Follow the link here According to Android documentation - “Update or remove assets that involve color. The system ignores all non-alpha channels in action icons and in the main notification icon. You should assume that these icons will be alpha-only. The system draws notification icons in white and action icons in dark gray.” Now this is easy to miss and I have seen many apps that are live in the app store with thousands of users who haven’t followed the mentioned guidelines. So let me explain in detail how you can convert your notification icon to an Android friendly one with a few clicks. In your favourite image editor open up your icon file. Convert all parts of the image that you don’t want to show to transparent pixels. All colors and non transparent pixels are displayed in white.

Ajeett
  • 814
  • 2
  • 7
  • 18