问题
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