How to clear count badge after clearing data and uninstall application in android?

痞子三分冷 提交于 2019-12-11 03:17:00

问题


The problem is when I install application and use it, it shows count badge on application icon. Now when I un-install application (while count badge is being displayed on application icon), and re-install the application, it again shows badge count on application icon.

(Note:- It iss showing last badge count when application was un-installed)

My problem is :

  1. Why badge count is being displayed after re-installing application?

  2. Do un-installing an application not clear its whole data?

  3. Can I clear the badge count when I un-install the application?

If its not possible, then can anybody provide me any link for the same?

I integrated badge count with the help of the following link:-

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


回答1:


The question/answer you link actually has the answer on how to clear badges.

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

So just call this method appropriately to clear the badge.

For example, check if first time loading app since fresh install, then apply.

  // 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();
  }

Read origional question/answer for more info



来源:https://stackoverflow.com/questions/24055413/how-to-clear-count-badge-after-clearing-data-and-uninstall-application-in-androi

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