Android App 图标Number设置

2018-02-23  本文已影响0人  super小立立

Android App 图标Number设置

源码获取地址 :

https://github.com/beiliao-mobile/BadgeNumberManager

获取手机注册名称

static {
    //硬件制造商
    String manufacturer = Build.MANUFACTURER;
    if (manufacturer.equalsIgnoreCase(MobileBrand.HUAWEI)) {
        IMPL = new ImplHuaWei();
    } else if (manufacturer.equalsIgnoreCase(MobileBrand.XIAOMI)) {
        IMPL = new ImplXiaoMi();
    } else if (manufacturer.equalsIgnoreCase(MobileBrand.VIVO)) {
        IMPL = new ImplVIVO();
    } else if (manufacturer.equalsIgnoreCase(MobileBrand.OPPO)) {
        IMPL = new ImplOPPO();
    } else {
        IMPL = new ImplBase();
    }
}

分别为对应的手机设置角标

private void setXiaomiBadgeNumber() {
        NotificationManager notificationManager = (NotificationManager) MainActivity.this.
                getSystemService(Context.NOTIFICATION_SERVICE);
        Notification notification = new NotificationCompat.Builder(MainActivity.this)
                .setSmallIcon(MainActivity.this.getApplicationInfo().icon)
                .setWhen(System.currentTimeMillis())
                .setContentTitle("推送标题")
                .setContentText("我是推送内容")
                .setTicker("ticker")
                .setAutoCancel(true)
                .build();
        //相邻的两次角标设置如果数字相同的话,好像下一次会不生效
        BadgeNumberManagerXiaoMi.setBadgeNumber(notification,mCount++);
        notificationManager.notify(1000, notification);
        Toast.makeText(MainActivity.this, "设置桌面角标成功", Toast.LENGTH_SHORT).show();

    }

//设置角标 (小米除外)
BadgeNumberManager.from(MainActivity.this).setBadgeNumber(0);
//清除角标
BadgeNumberManager.from(MainActivity.this).setBadgeNumber(0);

上一篇下一篇

猜你喜欢

热点阅读