I'm trying to use a vibration pattern when vibrating the phone. I'm using:
Vibrator v = (Vibrator) this.getSystemService(Context.VIBRATOR_SERVICE);
// Vibrate for 500 milliseconds
long[] longs = { 2, 0, 0, 0, 2, 0 , 0, 0, 2 };
v.vibrate(longs, 1);
and it just doesn't stop vibrating.
v.vibrate(longs, -1); it doesn't vibrate at all.v.vibrate(longs, 0); it doesn't vibrate at all.v.vibrate(longs, 2); or any number higher than 1, it vibrates indefinitely.I've read the documentation and some tutorials and I don't think I've done anything wrong here. Why isn't it vibrating properly?
Note: I use other apps that vibrate in patterns properly so I know it's not an issue with my phone.
You should read the documentation for vibrate().
With 2, 0, 0, 0, 2, 0 , 0, 0, 2, you are saying: "wait for 2 ms, vibrate for 0 ms, wait for 0 ms, vibrate for 0 ms, wait for 2 ms, vibrate for 0 ms, wait for 0 ms, vibrate for 0 ms, wait for 2 ms". Obviously, this pattern never vibrates, unless you repeat the pattern (which has an odd number of intervals).
When you pass anything other than -1 as the second argument, the pattern is repeated using the second argument as the index into the pattern at which to start repeating. Since you never seem to call v.cancel(), this repetition never ends, causing endless vibration (because at some point in the repetition, you will have non-0 vibration interval).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With