Firebase通知徽章android

时间:2017-12-07 11:39:01

标签: android firebase firebase-cloud-messaging

我正在使用firebase通知。这是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
    }
}

我需要将图标徽章计数设置为我的值,但Firebase会将其设置为通知计数。我正在尝试使用ShortcutBadger library,但它不适用于firebase通知。仅在以编程方式创建通知时才起作用(例如,通过按钮)。有什么想法吗?

0 个答案:

没有答案