How to Display Count of Notifications in App Launcher Icon

How to display count of notifications in app launcher icon

Android ("vanilla" android without custom launchers and touch interfaces) does not allow changing of the application icon, because it is sealed in the .apk tightly once the program is compiled. There is no way to change it to a 'drawable' programmatically using standard APIs. You may achieve your goal by using a widget instead of an icon. Widgets are customisable. Please read this :http://www.cnet.com/8301-19736_1-10278814-251.html and this http://developer.android.com/guide/topics/appwidgets/index.html.
Also look here: https://github.com/jgilfelt/android-viewbadger. It can help you.

As for badge numbers. As I said before - there is no standard way for doing this. But we all know that Android is an open operating system and we can do everything we want with it, so the only way to add a badge number - is either to use some 3-rd party apps or custom launchers, or front-end touch interfaces: Samsung TouchWiz or Sony Xperia's interface. Other answers use this capabilities and you can search for this on stackoverflow, e.g. here. But I will repeat one more time: there is no standard API for this and I want to say it is a bad practice. App's icon notification badge is an iOS pattern and it should not be used in Android apps anyway. In Andrioid there is a status bar notifications for these purposes:http://developer.android.com/guide/topics/ui/notifiers/notifications.html
So, if Facebook or someone other use this - it is not a common pattern or trend we should consider. But if you insist anyway and don't want to use home screen widgets then look here, please:

How does Facebook add badge numbers on app icon in Android?

As you see this is not an actual Facebook app it's TouchWiz. In vanilla android this can be achieved with Nova Launcher http://forums.androidcentral.com/android-applications/199709-how-guide-global-badge-notifications.html
So if you will see icon badges somewhere, be sure it is either a 3-rd party launcher or touch interface (frontend wrapper). May be sometime Google will add this capability to the standard Android API.

How to show notification count on app icon like Facebook?

Unfortunately you cant achieve this for all android devices.

Certain manufacturers (e.g. Samsung or Sony) have included this functionality into their customised Android launchers. Also some 3rd-party launchers (e.g. Nova Launcher) have included an API to accomplish this.

Some related posts for more information:

  • How does Facebook add badge numbers on app icon in Android?
  • https://stackoverflow.com/questions/18205569/does-samsung-modifies-its-android-roms-to-have-badges-on-email-and-sms-icons?rq=1
  • adding notification badge on app icon in android
  • How to interface with the BadgeProvider on Samsung phones to add a count to the app icon?
  • How to add a notification badge/count to application icon on Sony Xperia devices?
  • How to make application badge on android?
  • How to display count of notifications in app launcher icon

And some libraries that might be helpful:

  • Samsung badger

  • ShortcutBadger

  • Badges

and more...

How can i show the badge count on app icon in android? ShortcutBadger does not work, I don't want to use widget

you could generate the local notification with custom count.

example :

Android Doc

Kotlin:

var notification = NotificationCompat.Builder(this@MainActivity, CHANNEL_ID)
.setContentTitle("New Messages")
.setContentText("You've received 3 new messages.")
.setSmallIcon(R.drawable.ic_notify_status)
.setNumber(3)
.build()

Java:

Notification notification = new NotificationCompat.Builder(MainActivity.this, CHANNEL_ID)
.setContentTitle("New Messages")
.setContentText("You've received 3 new messages.")
.setSmallIcon(R.drawable.ic_notify_status)
.setNumber(3)
.build();

following will trigger the notification.

NotificationManager notificationManager = (NotificationManager) getContext().getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(1, notificationBuilder.build());

How to display unread count to the android app icon?

Unfortunately, You can't do that on application icon. Android doesn't allow that.

But you can do that using widget.
There are many question related this, check it first.

Question 1

Question 2

Question 3

Widget Example

Widget Link

Update : 24/04/2015

Now this is possible for some launcher app.

Check this ShortcutBadger and BadgeUtils

Update

Android allow Modify a Notification Badge from Android 8.0 (PI level 26).

Notification Count Badge in Android App Icon

Android O introduces notification badges:

https://developer.android.com/preview/features/notification-badges.html

They show the number of notifications with a long-press on the icon. It will be awhile before O has widespread adoption, though.



Related Topics



Leave a reply



Submit