Android 为什么振动不会';你不能在安卓P(API 28)上工作吗?
我试图在更改seekbar的值时实现触觉反馈。 它在安卓pre-P上正常工作。在安卓P上根本不工作。 代码:Android 为什么振动不会';你不能在安卓P(API 28)上工作吗?,android,kotlin,vibration,android-9.0-pie,haptic-feedback,Android,Kotlin,Vibration,Android 9.0 Pie,Haptic Feedback,我试图在更改seekbar的值时实现触觉反馈。 它在安卓pre-P上正常工作。在安卓P上根本不工作。 代码: 用户必须在设置->可访问性->振动->触摸振动中启用触摸振动: 没有它,短振动(小于5秒)将无法工作。对我来说,这不是很直观,所以我决定把它贴在这里,就像迈克说的那样。 但对于android Pie-设置->声音和振动->系统声音和振动->触摸振动 private val vibrator = context.getSystemService(Context.VIBRATOR_SERVI
用户必须在设置->可访问性->振动->触摸振动中启用触摸振动: 没有它,短振动(小于5秒)将无法工作。对我来说,这不是很直观,所以我决定把它贴在这里,就像迈克说的那样。 但对于android Pie-设置->声音和振动->系统声音和振动->触摸振动
private val vibrator = context.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator?
private val effect by lazy { VibrationEffect.createOneShot(VIBRATION_DURATION, 50)}
...
fun vibrate() {
if (vibrator == null || !vibrator.hasVibrator()) {
return
}
vibrator.cancel()
vibrator.vibrate(effect)