通知:当应用程序在后台时,“操作”按钮不可见

时间:2020-01-09 09:05:06

标签: android firebase push-notification notifications background

当应用程序处于后台时,我无法获得通知中的操作按钮。仅在应用程序位于前台时有效。

notificationManager.createNotificationChannel(notificationChannel)

val builder = NotificationCompat.Builder(this, getString(R.string.channel_id))
builder
        .setStyle(NotificationCompat.BigTextStyle(builder)
        .bigText(message)
        .setBigContentTitle(title)
        .setSummaryText(getString(R.string.app_name)))
        .setContentTitle(title)
        .setContentText(message)
        .setSmallIcon(R.drawable.ic_notification)
        .setLargeIcon(BitmapFactory.decodeResource(this@FirebaseService.resources, R.mipmap.ic_launcher))
        .setSound(defaultSoundUri)
        .setFullScreenIntent(null, true)
        .setAutoCancel(true)
        .setChannelId(getString(R.string.channel_id))
        .setColor(ContextCompat.getColor(applicationContext, R.color.colorPrimary))
        .setPriority(NotificationCompat.PRIORITY_HIGH)
        .setContentIntent(pendingIntent)
        .addAction(R.drawable.ic_notification, "Test", pendingIntent)

val nm = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
nm.notify(0, builder.build())

0 个答案:

没有答案