简体   繁体   中英

Android push notification icon LIght theme issue

I know this question is asked so many time related to Push notification status bar icon, but my problem is a little bit different.

I am using FCM push notification, my notification is coming properly. I have set notification icon for pre-lollipop and more then lollipop version. My notification icon is showing properly in dark theme devices like MOTO-G 5+, but when I check the same notification on light theme device like Samsung Galaxy Edge 7.0, my notification icon turns white as per app theme, but in another app, the notification icon is looking properly. I saw many example solution, but they did not help with my problem.

I am using following code :

  PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ila_app_icon);
    long when = System.currentTimeMillis();

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
    notificationBuilder.setContentText(message)
            .setContentIntent(pendingIntent)
            // .setColor(getNotificationColor())
            .setSmallIcon(getNotificationIcon(notificationBuilder))
            .setWhen(when)
            .setSound(defaultSoundUri)
            .setLargeIcon(bitmap);

    Random random = new Random();
    int uniqueIntegerNumber = random.nextInt(9999 - 1000) + 1000;
    notificationManager.notify(uniqueIntegerNumber, notificationBuilder.build());

Get notification icon method :-

  private int getNotificationIcon(NotificationCompat.Builder notificationBuilder) {

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        int color = 0x008000;
        notificationBuilder.setColor(color);
        return R.drawable.notification_white;

    }
    return R.drawable.ila_app_icon;
}

I also tried setColor property, but that also doesn't work.

1) Light Theme ( Here the white flag icon )

在此处输入图片说明 Here is the screen shot :-

在此处输入图片说明

2) Dark Theme :-

在此处输入图片说明

After all searching and other things i found my solution,everything was working well expect the notification icon, the icon was keeping little bit pixel of different color.

We can create the notification icon from the following link, it makes our icon transparent for notification

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM