0

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?

ReyAnthonyRenacia
  • 17,219
  • 5
  • 37
  • 56
fHate
  • 195
  • 3
  • 9
  • 1
    Please check [this question](https://stackoverflow.com/questions/39326508/fcm-setting-badge-in-onmessagereceived), looks pretty similar to what you're looking for! – dalla92 Dec 07 '17 at 15:01

0 Answers0