Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to Show Badge Count on App Icon in Android App's Launcher

    • 0
    • 0
    • 0
    • 0
    • 1
    • 0
    • 1
    • 0
    • 7.14k
    Comment on it

    As a badge count there is no standard way of doing this. However, one of the ways to do it in a simple way is by adding badge num on your application icon in launcher. It is handled by using a broadcast receiver. All the handset doesn't provide badge count, it fully depends on the manufacturer. Badges count function works really well with LG, Sony, Samsung, HTC.

     

     

    For better understanding, let’s see an example, how badges are shown in Sony Ericsson and Samsung handsets:

    1. Declare the permission in your manifest file.
      <uses-permission adroid:name="com.sonyericsson.home.permission.BROADCAST_BADGE />
    2. Updating the badge count in the application icon.
      int badgeCount = 1;
      ShortcutBadger.applyCount(context, badgeCount);
       
    3.  Broadcast an Intent to the BadgeReceiver to show the badge on app.
      Intent intent = new Intent();
      intent.setAction("com.sonyericsson.home.action.UPDATE_BADGE");
      intent.putExtra("com.sonyericsson.home.intent.extra.badge.ACTIVITY_NAME", "com.yourdomain.yourapp.MainActivity");
      intent.putExtra("com.sonyericsson.home.intent.extra.badge.SHOW_MESSAGE", true);
      intent.putExtra("com.sonyericsson.home.intent.extra.badge.MESSAGE", "99");
      intent.putExtra("com.sonyericsson.home.intent.extra.badge.PACKAGE_NAME", "com.yourdomain.yourapp");
      
      sendBroadcast(intent)
    4. Once you see, clear notification badge from preference and also with badge count simply send a new broadcast, this time with SHOW_MESSAGE set to false: 
      Intent intent = new Intent();
      intent.setAction("com.sonyericsson.home.action.UPDATE_BADGE");
      intent.putExtra("com.sonyericsson.home.intent.extra.badge.ACTIVITY_NAME", launcherClassName);
      intent.putExtra("com.sonyericsson.home.intent.extra.badge.SHOW_MESSAGE", false);
      intent.putExtra("com.sonyericsson.home.intent.extra.badge.MESSAGE", String.valueOf(0));
      intent.putExtra("com.sonyericsson.home.intent.extra.badge.PACKAGE_NAME", context.getPackageName());
      context.sendBroadcast(intent);
      

      com.sonyericsson.home.intent.extra.badge.ACTIVITY_NAME : name of your app mainActivity use to know which icon to show the badge.
       

      com.sonyericsson.home.intent.extra.badge.SHOW_MESSAGE: true/false indicate you want to show badge or not.
       

      com.sonyericsson.home.intent.extra.badge.MESSAGE: display the number of badge.

      com.sonyericsson.home.intent.extra.badge.PACKAGE_NAME: your application Package name.
       

    5. Samsung content provider opposite to Sony, Broadcast an intent for Samsung 
      Intent intent = new Intent("android.intent.action.BADGE_COUNT_UPDATE");
      intent.putExtra("badge_count", count);       
      intent.putExtra("badge_count_package_name", context.getPackageName());  
      intent.putExtra("badge_count_class_name", launcherClassName);
      sendBroadcast(intent);

       

    6. clear notification badge from Samsung : set count zero.
      intent.putExtra("badge_count", 0);
    How to Show Badge Count on App Icon in Android App's Launcher

 1 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: