How Does Facebook Add Badge Numbers on App Icon in Android

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 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 set badge number in home screen app icon android programatically?

There is popular github that works app icon badges for most Android devices. Sure still some platform, some devices didn't support that. But those libraries almost cover all of the devices that support app icon badges.

https://github.com/leolin310148/ShortcutBadger

So to your question, No.
Because Android framework didn't define the app notification badges before.(I am not sure if Android default framework have it now. I've been search the keyword of BADGE_COUNT_UPDATE in the ASOP android7 and nothing found) So all those custom badges are made by device manufacturer framework developer.

You can check how they setup badges numbers for each manufacturer here

https://github.com/leolin310148/ShortcutBadger/tree/master/ShortcutBadger/src/main/java/me/leolin/shortcutbadger/impl

To another question. I use keyword badge to search the ASOP source code and didn't find any noticeable part about app icon badges. And even there is one inbuilt framework method about this after certain version of android. The framework still cannot cover all the devices before the certain version. So not quite sure what do you mean by confidential app, but using libraries is the first choice to cover most android devices based on the real situation like this.

Android - how to add a badge count to an application icon?

It is currently not possible to target "all android devices", only for some.

Certain manufacturers (e.g. Samsung notably) 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.

Stock Android does not offer this functionality at the moment on the standard launcher.


I have just seen that this is a duplicate of:

  • Is there a way to add a badge to an application icon in Android?

There are many other related posts about this type of thing:

  • 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

You can find more information there.

Not all apps are in the notification number badge list

You are advised to use Huawei Push Kit.

According to the document , Push Kit provides an API for setting badges on the server. A badge number indicates the number of unread messages. You can encapsulate badge parameters in messages. For notification messages, Push Kit will display the badge number on the app icon. For data messages, your app needs to call the getBadgeNumber method to obtain badge parameters from each message and display the badge number.

Sample code for setting a badge on the server:

{
"validate_only": false,
"message": {
"notification": {
"title": "message title ",
"body": "message body"
},
"android": {
"notification": {
"click_action": {
"type": 2,
"url": "https://example.com"
},
"badge": {
"add_num": 1,
"class": "com.huawei.codelabpush.MainActivity",
"set_num": 10
}
},
"ttl": "1000"
},
"token": [
"pushtoken1"
]
}
}

For details about badge development on the client, please refer to Interface Description for Badging on Huawei Desktop.

Note: If you have any queries about Push kit, please feel free to contact us back.



Related Topics



Leave a reply



Submit