问题描述
我正在尝试对本地通知使用自定义振动。读了一点后,我在通知频道中设置了自定义振动模式,如下所示:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val notificationChannel =
NotificationChannel(NotificationChannels.CHANNEL_ID,channelName,importance)
...
notificationChannel.enableVibration(true)
notificationChannel.vibrationPattern = vibrationPattern
notificationmanager.createNotificationChannel(notificationChannel)
}
但它只振动一次并且只执行前四个索引。
例如,如果我的模式如下所示:
val vibrationPattern = longArrayOf(
0,200,500,50,50)
它只在第一行振动并停止。振动等价于:
val vibrationPattern = longArrayOf(0,50)
我有一个想法,将模式设置为看起来像最后一个,并将系统设置为重复几次,但到目前为止我还没有找到方法。
我很乐意在这里得到帮助。
解决方法
使用这个:
notification.flags = Notification.FLAG_INSISTENT
在放入NotificationManager.notify
之前