4

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

Nadeem Aslam
  • 123
  • 1
  • 7

1 Answers1

2

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());
Nakul
  • 1,313
  • 19
  • 26