Guillaume Brunerie
Guillaume Brunerie

Reputation: 5381

navigator.vibrate on Android only works for vibrations longer than one second

I'm trying to get haptic feedback in my web-based game on Android, but I can't get navigator.vibrate to work properly.

More precisely, navigator.vibrate(1000) doesn't do anything at all (it only returns true), while navigator.vibrate(1001) vibrates for one second. Values higher than 1000 seem to work, while lower values do not (and obviously one second is way too long for haptic feedback). I tried to cancel the vibration in a setTimeout, but navigator.vibrate(0) doesn't seem to work either.

I'm not in silent mode, none of the various volume sliders is zero, I've activated all vibration related settings I could find, and the call to navigator.vibrate happens on user interaction. I couldn't find any information on Google or here that could explain this behavior. Anything has an idea what's wrong and how/whether I can fix it?

Upvotes: 0

Views: 81

Answers (1)

mayankk28
mayankk28

Reputation: 1

You can try using vibration pattern instead of single duration like

navigator.vibrate([500, 100, 500]); // Vibrate for 500ms, pause for 100ms, then vibrate for 500ms

If navigator.vibrate(0) doesn’t stop the vibration, you can try using navigator.vibrate([]) or navigator.vibrate([0]) as a workaround.

Upvotes: 0

Related Questions