在某些设备上,.performHapticFeedback 会默默失败,无法知道触觉反馈是否成功,在这种设备上,触觉反馈设置为 true。
有没有办法知道设备是否支持触觉反馈,或者触觉反馈是否执行?
(该设备是我用于测试的安卓2.3 Galaxy W,我认为它不支持触觉反馈,因为没有触觉反馈设置)
在某些设备上,.performHapticFeedback 会默默失败,无法知道触觉反馈是否成功,在这种设备上,触觉反馈设置为 true。
有没有办法知道设备是否支持触觉反馈,或者触觉反馈是否执行?
(该设备是我用于测试的安卓2.3 Galaxy W,我认为它不支持触觉反馈,因为没有触觉反馈设置)
Vibrator mVibrator = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
boolean isVibrator = mVibrator.hasVibrator();
它检查硬件是否有振动器。
如果您想根据支持情况使设备振动,需要添加权限。android.permission.VIBRATE
然后调用 mVibrator.vibrate(long millisenonds)
我的猜测是这样的:
在你的活动/服务代码中,尝试像这样检查振动器服务是否可用:
// Get instance of Vibrator from current Context
Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
if(v == null){
//no haptic feedback is possible
}
else{
//haptic feedback is a possible feature
}