Как очистить уведомление о типе действия при щелчке действия в android Q? - PullRequest
0 голосов
/ 07 января 2020

В android 10 я использую уведомление типа ответа. Я хочу очистить это уведомление об ответном действии. Для очистки уведомления я использую этот код:

 val notificationManager =
        context.getSystemService(AppCompatActivity.NOTIFICATION_SERVICE) as NotificationManager
    notificationManager.cancel(notifyId)

Для переменной notifyId я передаю идентификатор уведомления.

этот код работает для всех android версии за исключением android версия 10.

Используется для создания действия ответа:

val replyAction = NotificationCompat.Action.Builder(
            R.drawable.ic_send,
            btnlable,
            getReplyPendingIntent(
                notificationId,
                title,
                msg,
                senderName,
                action,
                apiName,
                type,
                intentType
            )
        )
            .addRemoteInput(remoteInput)
            .setAllowGeneratedReplies(true)
            .build()

Используется для создания уведомления:

val notification = NotificationCompat.Builder(mContext, channelID)
            .setSmallIcon(R.drawable.noti_icon)
            .setContentTitle(title)   //Set the title of Notification
            .setContentText(msg)    //Set the text for notification
            .addAction(replyAction)
            .setSound(null)
            .setWhen(getTimeMilliSec(timeStamp))
            .setLargeIcon(BitmapFactory.decodeResource(mContext.resources, R.drawable.logo))
            .setContentIntent(resultPendingIntent)
            .build();
        notification.flags = Notification.FLAG_AUTO_CANCEL

1 Ответ

0 голосов
/ 31 января 2020

Я не знаю, где вы вызываете метод .cancel, но я делаю это для метода onHandleIntent класса, который наследуется от класса IntentService, и он работает:

class ApplicationIntentService() : IntentService("AppIntentService") {

    companion object{
        const val BIG_TEXT_STYLE_ACTION1_NAME = "big_text_style.action1"
    }

    override fun onHandleIntent(intent: Intent?) {
        var notificationManager = applicationContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager

        if (intent?.action == BIG_TEXT_STYLE_ACTION1_NAME) {
            notificationManager.cancel(0)
        }
    }
}

Если вы тоже это сделали, сделайте обязательно зарегистрируйте свою реализацию IntentService в Manifest. xml:

    <service
        android:name=".Services.ApplicationIntentService"
        android:exported="false">
    </service>
...