4

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?

7
  • Why copy iOS's UI? Try to invent something new, please.
    – Raptor
    Mar 5, 2014 at 9:37
  • 1
    @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. Mar 5, 2014 at 10:07
  • does Facebook native app has badge for all Android devices & launchers?
    – Raptor
    Mar 5, 2014 at 10:50
  • no it doesn't but some devices have that facility. Mar 5, 2014 at 11:09
  • have you got any solution? Oct 16, 2014 at 10:58

3 Answers 3

3

I also faced same problem but perfect solution for your question is below link:

https://derivedcode.wordpress.com/2013/10/09/showing-badge-or-count-in-android-app-icon/

1
  • The link is correct and seems exact solution... thanks @androiddeveloper2011
    – Kushal
    Mar 30, 2016 at 11:11
1

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!

1
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.