我想显示低优先级的折叠通知,例如android:
坍塌的
并展开
这是我的代码: 通知频道的创建:
private fun createNotificationChannel() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val name = getString(R.string.name)
val descriptionText = getString(R.string.description)
val importance = NotificationManager.IMPORTANCE_MIN
val channel = NotificationChannel(CHANNEL_ID, name, importance).apply {
description = descriptionText
}
// Register the channel with the system
val notificationManager: NotificationManager =
getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.createNotificationChannel(channel)
}
}
和通知本身
createNotificationChannel()
val intent = Intent(this, MyActivity::class.java).apply {
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
}
val pendingIntent: PendingIntent = PendingIntent.getActivity(this, 0, intent, 0)
val notification: Notification = NotificationCompat.Builder(this, CHANNEL_ID)
.setContentTitle(getString(R.string.notification_title))
.setContentText(getString(R.string.notification_message))
.setSmallIcon(R.drawable.ic_light_black_24dp)
.setPriority(NotificationCompat.PRIORITY_LOW)
.setContentIntent(pendingIntent)
.build()
startForeground(SERVICE_NOTIFICATION_ID, notification)