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

8

我正在尝试更改通知图标,在模拟器中一切正常:

enter image description here

enter image description here

enter image description here

enter image description here

这是我想要的(在模拟器API级别22(android 5.1.1)上测试过),但是当我在我的真实手机(小米红米3 prime,MIUI 8.0.1)上运行此应用程序时,通知看起来非常非常不同。这些通知图标没有显示(只有默认应用程序图标)。

但是...为什么?我现在该怎么办?

这是我的代码:

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());

只是一个非常简单的通知...有人能告诉我,出了什么问题吗?或者MIUI将所有通知图标关闭并将其设置为默认应用程序启动图标?

谢谢!

编辑:我的手机上的通知看起来像这样...

enter image description here enter image description here

2个回答

11

我遇到了同样的问题,但 Juan Pablo(在评论Java Android - Redmi 3 (MIUI) - Notification icons cannot be changed?中)给了我一个线索,现在我有了解决方案:

//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) {

    }

现在它按预期工作。


@sikor 有没有关于所有可用的 android.app.MiuiNotification 方法和字段的文档? - jkasten
1
@jkasten 我没有找到任何相关的信息。我花了一些时间搜索,但是我所找到的只有这个链接:http://www.bkjia.com/Androidjc/1119525.html - sikor
@sikor 发现得真好。必须将其标记为正确答案。 - Arnav M.
兄弟,你救了我的命。 - ucMedia

5

这是MIUI系统的行为。默认情况下,它将应用程序图标作为通知图标,无法显示不同的通知图标。


这件事发生在我一年前。你能接受这个答案吗?如果有人了解MIUI,可以参考一下。 - subrahmanyam boyapati
3
我也遇到了小米红米Note 3的同样问题。通过调试,我发现通知中有一个名为ExtraNotification的字段,类型为MiUiNotification,在其中有一个标志:customizedIcon=false。也许如果更改此标志,则可以显示个性化图标。 - Juan Pablo
@JuanPablo,关于自定义布局是否有类似的东西?它们似乎也没有正确显示。 - Mark
1
@Mark 如果你感兴趣的话,我在使用MIUI时setCustomContentView()和setCustomBigContentView()都能正常工作,使用NotificationCompat.Builder和targetSdkVersion 28也没有任何问题。 - Alex
1
抱歉,@Mark,Google Play控制台未提供有关MIUI版本的信息。为了修复状态栏图标的错误,我与Redmi 4X和红米Note 5A客户合作,两者均带有原始MIUI启动器。他们提供了使用我的自定义布局的通知内容屏幕截图,效果如预期。 - Alex
显示剩余4条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接