Reputation: 53
how can we show a badge count on app icon when the app is closed / at background? As far as I know, I can use the third party lib (like ShortcutBadger)to set the count on the app icon but the problem is when android app is at background, notification is handled at the system tray, and my code will not be processed (please notice me if I am wrong). how can I set the count number on app icon??
Upvotes: 2
Views: 1359
Reputation: 327
you can use something like this
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();
.setNumber(messageCount) will be added as luncher icon badge in api level 26
Upvotes: 2