3
votes

I want to display push notification badge in all devices like Samsung,Sony,Lg etc., I want to display notification badge like facebook native application. i did small research for that in my result Android relies on the Notification Center to give the user indication about incoming events. So technically, if your app already does that, you don't have to do anything else. but some devices have own framework badge receivers.

In sony

http://marcusforsberg.net/blog/android-notification-badge-app-icon-sony/

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);

In Samsung

https://github.com/shafty023/SamsungBadger

Add the following permissions to your application's AndroidManifest.xml

uses-permission android:name="com.sec.android.provider.badge.permission.READ" 
uses-permission android:name="com.sec.android.provider.badge.permission.WRITE" 

To badge your icon with "1"

Context context = getApplicationContext();
if (Badge.isBadgingSupported(context)) {
    Badge badge = new Badge();
    badge.mPackage = context.getPackageName();
    badge.mClass = getClass().getName();
    badge.mBadgeCount = 1;
    badge.save(context);
}

Is there any other framework badge receivers code is available?

3
Why copy iOS's UI? Try to invent something new, please.Raptor
@Raptor: yes,you are right but some users wants to release same UI like iOS. they told facebook native app have badges why our app can't do that. sorry for my poor english.prasad thangavel
does Facebook native app has badge for all Android devices & launchers?Raptor
no it doesn't but some devices have that facility.prasad thangavel
have you got any solution?micky

3 Answers

1
votes

Try to use this libriary ShortcutBadger.

Description from github:

ShortcutBadger: The ShortcutBadger makes your Android App showing the count of unread messages as a badge on your App shortcut!

0
votes

This works for me:

1) Add mavenCentral to your build script.

 repositories {
    mavenCentral()
}

2) Add dependencies for ShortcutBadger, it's available from maven now.

 dependencies {
        compile 'me.leolin:ShortcutBadger:1.1.4@aar'
    }

3) Add the codes below:

int badgeCount = 1;
ShortcutBadger.applyCount(context, badgeCount); //for 1.1.4
ShortcutBadger.with(getApplicationContext()).count(badgeCount); //for 1.1.3

4) If you want to remove the badge
 ShortcutBadger.removeCount(context); //for 1.1.4
ShortcutBadger.with(getApplicationContext()).remove();  //for 1.1.3

 or

ShortcutBadger.applyCount(context, 0); //for 1.1.4
ShortcutBadger.with(getApplicationContext()).count(0); //for 1.1.3