检测设备是否在振动?

use*_*231 6 events android vibration android-vibration

我使用下面的代码来振动设备.

public void vibrator() {
    try {
        Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
        vibrator.vibrate(5000);
    } catch (Exception e) {
        Log.d(TAG, "vibrator exception: " + e);
    }
}
Run Code Online (Sandbox Code Playgroud)

我们能以编程方式检测此事件(检查是设备振动)吗?

ant*_*dvr 2

不,你不能。

同样的问题在这里

您可以仅检查设备是否支持振动:

Vibrator mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
boolean hasVibrator = mVibrator.hasVibrator();
Run Code Online (Sandbox Code Playgroud)

查看更多: