简体   繁体   English

Java Android - Redmi 3(MIUI) - 通知图标无法更改?

[英]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. 这就是我想要的(在模拟器API级别22(安卓5.1.1)上测试)但是,当我在我的真实手机中运行这个APP时(小米Redmi 3 prime与MIUI 8.0.1)也是android 5.1.1 - 通知看起来非常非常不同。 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? 或者只是MIUI关闭所有通知图标并将其设置为默认的应用程序启动图标?

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: 我有同样的问题,但Juan Pablo(评论Java Android - Redmi 3(MIUI) - 通知图标无法更改? )给了我一个线索,现在我有一个解决方案:

//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. 这是MIUI系统的行为。 You can not display different icons in notification, by default it takes app icon as notification icon. 您无法在通知中显示不同的图标,默认情况下,它会将应用程序图标作为通知图标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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