Уведомление Android с действиями: кнопка отображается три раза - PullRequest
0 голосов
/ 04 декабря 2018

Я создаю Notification, используя NotificationCompat.Builder.Это уведомление получает кнопку действия:

    notification = notificationBuilder
        .setContentTitle(getString(R.string.blabla)).
        .setContentText("")
        .setSmallIcon(R.drawable.blabla)
        .setContentIntent(pendingIntentOpenApp)
        .addAction(android.R.drawable.ic_menu_close_clear_cancel, "Cancel", pendingIntentAction)
        .build();

Уведомление отображается, но действие повторяется три раза:

enter image description here

Iне могу понять, что я делаю неправильно, поэтому я ценю любую помощь.

1 Ответ

0 голосов
/ 04 декабря 2018

Вы можете создать уведомление, используя следующий код:

var mBuilder = NotificationCompat.Builder(this, channelId)
        .setSmallIcon(R.drawable.ic_notification)
        .setContentTitle("Title")
        .setContentText("Description")
        .setPriority(NotificationCompat.PRIORITY_DEFAULT)
        .addAction(R.drawable.ic_notification,"OK",pendingIntent)
        .setChannelId(chanelId).build()


val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    val mChanel = NotificationChannel(id, name, NotificationManager.IMPORTANCE_HIGH)
    notificationManager.createNotificationChannel(mChanel)
    notificationManager.notify(channelId, mBuilder)
}else{
    notificationManager.notify(channelId, mBuilder)
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...