I'm using firebase notifications. This is FirebaseMessagingService:
class mFirebaseMessagingService : FirebaseMessagingService() {
private lateinit var notification: Notification
private val badgeCount = 3 //value to show in badge
override fun onMessageReceived(remoteMessage: RemoteMessage) {
sendNotification(remoteMessage.notification.body)
}
private fun sendNotification(message: String) {
val intent = Intent(this, MainActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
val builder = NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.img)
.setLargeIcon(BitmapFactory.decodeResource(this.resources, R.drawable.img))
.setContentTitle(this.getString(R.string.app_name))
.setContentText(message)
.setAutoCancel(true)
notification = builder.build()
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.notify(0, notification)
ShortcutBadger.applyNotification(applicationContext, notification, badgeCount) //trying to use it
}
}
I need to set icon badge count to my value, but Firebase set it to count of notifications. I'm trying to use ShortcutBadger library but it doesn't work well with firebase notifications. Works only if notifications creating programmatically (by the button for example). Any idea?