我在文档中看到此方法:
public NotificationCompat.Builder setTimeoutAfter(long durationMs)
指定此通知应取消的时间(如果尚未取消。)>
文档没有提到兼容性,但是,当我尝试在低于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:/ ...
[setTimeoutAfter
仅在API级别26中添加。