0
votes

I want to update app icon badge count without push notifications(eg. Silent push). I simply want to update app badge count after reading any notifications inside the app similar to linkedIn, where its updating the count on app badge when am reading any notification. Currently I've implemented the solution where I am having payload from FCM with badge count and updating it with android notification builder with silent push notification channel configured.

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(messageCount)
    .build()

but that is not gonna work for me as I also need to update the count once I've read any notification inside the app. If I clear the notification from notification tray then count is also disappearing from app badge, is there any way that I can set that count without push notification within the app? Thanks in advance.

"I also need to update the count once I've read any notification inside the app" -- update the Notification with the new number, using code akin to what you show in your question. That code is unrelated to FCM and can be used wherever you need it.CommonsWare
I tried this, am trying to set count without push using above code but for this again I need to show silent push in notification trayAmmy Kang