Android пузыри - PullRequest
       32

Android пузыри

0 голосов
/ 29 марта 2020

Я пробую этот образец https://developer.android.com/guide/topics/ui/bubbles. Добавьте уведомление пузыря в мой проект. Но это не работает.

Я хочу проверить, работает пузырь или нет. Так что пузырьковая активность просто пустая.

В функции onCreate я создам канал уведомлений.

private fun createNotificationChannel() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        val name = getString(R.string.channel_name)
        val descriptionText = getString(R.string.channel_description)
        val importance = NotificationManager.IMPORTANCE_HIGH
        val channel = NotificationChannel(CHANNEL_ID, name, importance).apply {
            description = descriptionText
            setAllowBubbles(true)
        }

        notificationManager =
            getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
        notificationManager?.createNotificationChannel(channel)
    } 
}

По истечении времени таймера отправим пузырьковое уведомление.

private fun timeUpNotify() {
            val target = Intent(this, BubbleActivity::class.java)
            val bubbleIntent = PendingIntent.getActivity(this, 0, target, 0 /* flags */)

            val bubbleData = Notification.BubbleMetadata.Builder()
                .setDesiredHeight(600)
                .setIcon(Icon.createWithResource(this, R.drawable.ic_launcher_background))
                .setIntent(bubbleIntent)
                .build()

            val chatBot = Person.Builder()
                .setBot(true)
                .setName("BubbleBot")
                .setImportant(true)
                .build()

            val builder = Notification.Builder(this, CHANNEL_ID)
                .setContentIntent(bubbleIntent)
                .setSmallIcon(R.drawable.ic_launcher_background)
                .setBubbleMetadata(bubbleData)
                .addPerson(chatBot)

            notificationManager?.notify(CHANNEL_ID.toInt(), builder.build()) 
}

Но результат похож на эту картинку. изображение результата Если моя информация не ясна. Вот мой тестовый проект. https://drive.google.com/file/d/1ENXjX8Ci-fXwpjNfPh2yt5RoCahVUHH6/view?usp=sharing

Большое спасибо!

...