在android中清除数据并卸载应用程序后如何清除计数徽章?

时间:2014-06-05 08:37:58

标签: android android-install-apk android-hardware

问题是当我安装应用程序并使用它时,它会在应用程序图标上显示计数徽章。现在,当我卸载应用程序时(在应用程序图标上显示计数徽章时),并重新安装应用程序,它再次显示应用程序图标上的徽章计数。

(注意: - 在卸载应用程序时显示上次徽章计数)

我的问题是:

  1. 为什么重新安装应用程序后会显示徽章计数?

  2. 是否取消安装应用程序而不清除其整个数据?

  3. 我可以在卸载应用程序时清除徽章计数吗?

  4. 如果不可能,那么任何人都可以为我提供相同的链接吗?

    enter image description here

    我借助以下链接整合了徽章计数: -

    How to interface with the BadgeProvider on Samsung phones to add a count to the app icon?

1 个答案:

答案 0 :(得分:1)

您链接的问题/答案实际上有关于如何清除徽章的答案。

ContentValues cv = new ContentValues();
cv.put("badgecount", 0);
getContentResolver().update(Uri.parse("content://com.sec.badge/apps"), cv, "package=?", new String[] {getPackageName()});  

https://stackoverflow.com/a/20136484/940834

因此,只需适当调用此方法即可清除徽章。

例如,检查自新安装后是否首次加载应用程序,然后应用。

  // CHECK IF FIRST LOAD
  if(!PreferenceManager.getDefaultSharedPreferences(this).contains("NOTFIRSTLOAD"))
 {
       ContentValues cv = new ContentValues();
       cv.put("badgecount", 0);
       getContentResolver().update(Uri.parse("content://com.sec.badge/apps"), cv, "package=?", new String[] {getPackageName()});  

       // Store that its not first load 
       PreferenceManager.getDefaultSharedPreferences(this).edit().putInt("NOTFIRSTLOAD", 1).commit();
  }

阅读原始问题/答案以获取更多信息

相关问题