wjc
20 小时以前 2f5411b86c59706d31f6ec7de629d8f860725e46
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package com.hdl.photovoltaic.utils;
 
import android.app.NotificationManager;
import android.content.Context;
 
import me.leolin.shortcutbadger.ShortcutBadger;
 
public class BadgeUtils {
    // 设置角标数量
    public static void setBadgeCount(Context context, int count) {
        if (ShortcutBadger.isBadgeCounterSupported(context)) {
            ShortcutBadger.applyCount(context, count);
        }
    }
 
    // 清除角标(设置数量为0)
    public static void clearBadge(Context context) {
        if (ShortcutBadger.isBadgeCounterSupported(context)) {
            ShortcutBadger.removeCount(context);
        } else {
            // 备用方案
//            clearBadgeByManufacturer(context);
        }
    }
    /**
     * 清除所有通知
     */
    public static void cancelAllNotifications(Context context) {
        NotificationManager notificationManager =
                (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.cancelAll();
    }
}