我正在尝试更改通知图标,在模拟器中它是可以的:




这是我想要的(在模拟器API 22级(Android5.1.1)上测试),但是,当我在我的真实手机上运行这个应用程序时(小米红米3,带有MIUI 8.0.1),也是Android5.1.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关闭所有通知图标并将其设置为默认的应用程序启动图标?
谢谢!
编辑:我手机里的通知是这样的.


发布于 2016-10-20 05:32:09
这是MIUI系统的行为。您不能在通知中显示不同的图标,默认情况下它使用应用程序图标作为通知图标。
发布于 2016-11-20 19:27:04
我也遇到了同样的问题,但是Juan (在评论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) {
}现在,它发挥了预期的作用。
https://stackoverflow.com/questions/40146059
复制相似问题