// 让app logo显示消息数量
public void showCount() {
NotificationManager mNotificationManager = (NotificationManager) this
.getSystemService(Context.NOTIFICATION_SERVICE);
Notification.Builder builder = new Notification.Builder(this);
// .setContentTitle("title").setContentText("text").setSmallIcon(R.drawable.point_on).setAutoCancel(true);;
Notification notification = builder.build();
try {
Field field = notification.getClass().getDeclaredField("extraNotification");
Object extraNotification = field.get(notification);
Method method = extraNotification.getClass().getDeclaredMethod("setMessageCount", int.class);
method.invoke(extraNotification, allCount);
} catch (Exception e) {
e.printStackTrace();
}
mNotificationManager.notify(0, notification);
BadgeUtil.setBadgeCount(notification, context, allCount);
public void showCount() {
NotificationManager mNotificationManager = (NotificationManager) this
.getSystemService(Context.NOTIFICATION_SERVICE);
Notification.Builder builder = new Notification.Builder(this);
// .setContentTitle("title").setContentText("text").setSmallIcon(R.drawable.point_on).setAutoCancel(true);;
Notification notification = builder.build();
try {
Field field = notification.getClass().getDeclaredField("extraNotification");
Object extraNotification = field.get(notification);
Method method = extraNotification.getClass().getDeclaredMethod("setMessageCount", int.class);
method.invoke(extraNotification, allCount);
} catch (Exception e) {
e.printStackTrace();
}
mNotificationManager.notify(0, notification);
BadgeUtil.setBadgeCount(notification, context, allCount);
}
/*
* 应用启动图标未读消息数显示 工具类 (效果如:QQ、微信、未读短信 等应用图标)<br/>
* 这里包含了小米,sony,Samsung,htc,nova,huawei,zuk 全部亲测有效
* */
public class BadgeUtil {
/**
* Set badge count<br/>
* 针对 Samsung / xiaomi / sony 手机有效
* @param context The context of the application package.
* @param count Badge count to be set
*/
public static void setBadgeCount(Notification notification,Context context, int count) {
if (count <= 0) {
count = 0;
} else {
count = Math.max(0, Math.min(count, 99));
}
if (Build.MANUFACTURER.equalsIgnoreCase("