Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I used ShortcutBadger library for android but it is not working in my case. I tested it on various devices. I googled about it and possible solution can be use of widget. Is there any other solution? Apps like facebook whatsapp showing the badge count and that is visible in my phone.enter image description here

like image 539
Nadeem Aslam Avatar asked Oct 29 '25 07:10

Nadeem Aslam


1 Answers

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());
like image 180
Nakul Avatar answered Oct 31 '25 20:10

Nakul



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!