Как сделать свернутое компактное уведомление - PullRequest
0 голосов
/ 13 июня 2019

Я хочу показать свернутое уведомление с низким приоритетом, например, как androids: свернуто Collapsed default notification и расширенный enter image description here

Вот мой код: Создание канала уведомлений:

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)
...