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:
- Declare the permission in your manifest file.
<uses-permission adroid:name="com.sonyericsson.home.permission.BROADCAST_BADGE />
- Updating the badge count in the application icon.
int badgeCount = 1;
ShortcutBadger.applyCount(context, badgeCount);
- 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)
- 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.
- 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);
- clear notification badge from Samsung : set count zero.
intent.putExtra("badge_count", 0);
1 Comment(s)