NotificationCompat.Builder中的setTimeoutAfter不起作用

问题描述 投票:0回答:1

我在文档中看到此方法:

public NotificationCompat.Builder setTimeoutAfter(long durationMs)

指定此通知应取消的时间(如果尚未取消。)>

https://developer.android.com/reference/androidx/core/app/NotificationCompat.Builder.html#setTimeoutAfter(long)

文档没有提到兼容性,但是,当我尝试在低于API 26的设备上使用此方法时-它不起作用。我的代码:

// Init channel with default importance if api >= 26
initNotificationsChannel()

val notificationManager = NotificationManagerCompat.from(this)
val notification = NotificationCompat.Builder(this, channelId)
        .setContentTitle("Title")
        .setContentText("Text")
        .setSmallIcon(R.drawable.icon)
        .setTimeoutAfter(5000)
        .build()

notificationManager.notify(1, notification)

此行为是否是错误?

我在docs中看到此方法:public NotificationCompat.Builder setTimeoutAfter(long durationMs)指定应该取消此通知的时间(如果尚未取消的话)。 https:/ ...

android android-notifications
1个回答
0
投票

[setTimeoutAfter仅在API级别26中添加。

© www.soinside.com 2019 - 2024. All rights reserved.