已经在三星手机实现了桌面角标,但是在小米上就是不显示,问一下怎么样实现?
解决方案
50
public static void ShowBadge(Notification notification,int iNotifyCount)
{
try {
//this first
Field field = notification.getClass().getDeclaredField(“extraNotification”);
Object extraNotification = field.get(notification);
Method method = extraNotification.getClass().getDeclaredMethod(“setMessageCount”, int.class);
method.invoke(extraNotification, iNotifyCount);
} catch (Exception e) {
try {
Class miuiNotificationClass = Class.forName(“android.app.MiuiNotification”);
Object miuiNotification = miuiNotificationClass.newInstance();
Field field = miuiNotification.getClass().getDeclaredField(“messageCount”);
field.setAccessible(true);
try {
field.set(miuiNotification, iNotifyCount);// 设置信息数
} catch (Exception e1) {
field.set(miuiNotification, “” + iNotifyCount);// 设置信息数
}
field = notification.getClass().getField(“extraNotification”);
field.setAccessible(true);
field.set(notification, miuiNotification);
} catch (Exception e2) {
// TODO: handle exception
}
}
}
{
try {
//this first
Field field = notification.getClass().getDeclaredField(“extraNotification”);
Object extraNotification = field.get(notification);
Method method = extraNotification.getClass().getDeclaredMethod(“setMessageCount”, int.class);
method.invoke(extraNotification, iNotifyCount);
} catch (Exception e) {
try {
Class miuiNotificationClass = Class.forName(“android.app.MiuiNotification”);
Object miuiNotification = miuiNotificationClass.newInstance();
Field field = miuiNotification.getClass().getDeclaredField(“messageCount”);
field.setAccessible(true);
try {
field.set(miuiNotification, iNotifyCount);// 设置信息数
} catch (Exception e1) {
field.set(miuiNotification, “” + iNotifyCount);// 设置信息数
}
field = notification.getClass().getField(“extraNotification”);
field.setAccessible(true);
field.set(notification, miuiNotification);
} catch (Exception e2) {
// TODO: handle exception
}
}
}