• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

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

buffoon

Lurker
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:

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(messageCount)
        .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?
 
Back
Top Bottom