简体   繁体   中英

Java Android - Redmi 3 (MIUI) - Notification icons cannot be changed?

I'm trying to change notification icons and in emulator it is OK :

在此输入图像描述

在此输入图像描述

在此输入图像描述

在此输入图像描述

This is what I want (tested on emulator API level 22 (android 5.1.1)) BUT, when i'm running this APP in my real phone (Xiaomi Redmi 3 prime with MIUI 8.0.1) also android 5.1.1 - the notifications looks very very very differant. This notification icons does not showing (just a default application icon).

But... why? What can i do now?

Here is my code:

NotificationCompat.Builder b = new NotificationCompat.Builder(compat);
        b.setSmallIcon((state == STATE_STOPPED) ? R.drawable.ic_stat_remove : R.drawable.check);
        b.setContentText(content);
        b.setContentTitle(BASE_NOTIFICATION_TITLE);
        b.setOngoing(true);
        b.setAutoCancel(true);
        b.setColor((state == STATE_STOPPED) ? Color.RED : Color.rgb(22, 219, 28));

        NotificationManager m = (NotificationManager) compat.getSystemService(NOTIFICATION_SERVICE);
        m.notify(0, b.build());

Just a very simple notification... can someone tell me, what's wrong? Or just MIUI turns off all notification icons and set it to default app launch icons?

Thanks!

EDIT: notification in my phone looks like this...

在此输入图像描述 在此输入图像描述

I had the same problem, but Juan Pablo (in comment Java Android - Redmi 3 (MIUI) - Notification icons cannot be changed? ) gave me a clue and now I have a solution:

//notification is an object of class android.app.Notification
    try {
        Class miuiNotificationClass = Class.forName("android.app.MiuiNotification");
        Object miuiNotification = miuiNotificationClass.newInstance();
        Field field = miuiNotification.getClass().getDeclaredField("customizedIcon");
        field.setAccessible(true);

        field.set(miuiNotification, true);
        field = notification.getClass().getField("extraNotification");
        field.setAccessible(true);

        field.set(notification, miuiNotification);
    } catch (Exception e) {

    }

Now it works as it is expected.

This is behavior of MIUI system. You can not display different icons in notification, by default it takes app icon as notification icon.

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