1. Are you ready for the Galaxy S20? Here is everything we know so far!

How to set the notification badge count programatically without sending notification?

Discussion in 'Android Development' started by buffoon, Nov 19, 2019.

  1. buffoon

    buffoon Lurker
    Thread Starter

    I want to change the notification badge count, say, whenever the user clicks on a button. At the moment, the only way I know to change the notification badge count is by sending a notification like so:

    Code (Java):
    1. Notification notification = new NotificationCompat.Builder(MainActivity.this, CHANNEL_ID)
    2.         .setContentTitle("New Messages")
    3.         .setContentText("You've received 3 new messages.")
    4.         .setSmallIcon(R.drawable.ic_notify_status)
    5.         .setNumber(messageCount)
    6.         .build();
    I could technically send a notification every time the user presses the button, but that'd clutter the notification panel (as the goal here is to just change the badge count). So, is there anyway I can change the notification badge count without sending a notification?


Share This Page