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

I am trying to change the notification icons, but in the emulator, this is normal:

enter image description here

enter image description here

enter image description here

enter image description here

This is what I want (tested at API emulator level 22 (android 5.1.1)). BUT, when I run this APP on my real phone (Xiaomi Redmi 3 prime with MIUI 8.0.1), also android 5.1. 1 - notifications look very very different. Notification icons do not appear (default application icon only).

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 happened? Or just MIUI disables all notification icons and sets it to the default application launcher icons?

Thanks!

EDIT: The notification on my phone looks like this:

enter image description here enter image description here

+6
source share
2 answers

This is the behavior of the MIUI system. You cannot display different icons in the notification, by default the application icon is displayed as a notification icon.

+5
source

I had the same problem, but Juan Pablo (in the Java Android comment - Redmi 3 (MIUI) - notification icons cannot be changed? ) Gave me the key 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 expected.

+7
source

Source: https://habr.com/ru/post/1011497/


All Articles