为什么振动不适用于Android P(API 28)?

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

我正在尝试在更改搜索栏的值时实施触觉反馈。它在Android pre-P上正常工作。在Android P上它根本不起作用。码:

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)
android kotlin vibration android-9.0-pie haptic-feedback
1个回答
3
投票

事实证明用户必须在设置 - >辅助功能 - >振动 - >触摸振动中启用触摸振动:enter image description here

没有它,短暂的振动(少于5秒)将无法工作。对我来说,这不是很直观,所以我决定在这里发布

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