How to clear old badge count in android

谁都会走 提交于 2019-12-11 06:29:56

问题


I set "0" means its showing badge count was "1". how to clear my old badge count.

//Badge count set method

  public static void setBadge(Context mContext, int count) {
    String launcherClassName = getLauncherClassName(mContext);
    if (launcherClassName == null) {
        return;
    }
    Intent intent = new Intent("android.intent.action.BADGE_COUNT_UPDATE");
    intent.putExtra("badge_count", count);
    intent.putExtra("badge_count_package_name", mContext.getPackageName());
    intent.putExtra("badge_count_class_name", launcherClassName);
    mContext.sendBroadcast(intent);
}

//Find out our app and here return app package name.

 public static String getLauncherClassName(Context mContext) {

    PackageManager pm = mContext.getPackageManager();
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    List<ResolveInfo> resolveInfos = pm.queryIntentActivities(intent, 0);
    for (ResolveInfo resolveInfo : resolveInfos) {
        String pkgName = resolveInfo.activityInfo.applicationInfo.packageName;
        if (pkgName.equalsIgnoreCase(mContext.getPackageName())) {
            String className = resolveInfo.activityInfo.name;
            return className;
        }
    }
    return null;
}

回答1:


This can be done if using the https://github.com/leolin310148/ShortcutBadger library by calling the method as follows:

ShortcutBadger.applyCount(Context context, int badgeCount)

//or

ShortcutBadger.removeCount(Context context)


来源:https://stackoverflow.com/questions/39403950/how-to-clear-old-badge-count-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!