I wrote an Android application. Now, I want to make the device vibrate when a certain action occurs. How can I do this?
Above answers are perfect. However I wanted to vibrate my app exactly twice on button click and this small information is missing here, hence posting for future readers like me. :)
We have to follow as mentioned above and the only change will be in the vibrate pattern as below,
long[] pattern = {0, 100, 1000, 300};
v.vibrate(pattern, -1); //-1 is important
This will exactly vibrate twice. As we already know
One can go on and on mentioning delay and vibration alternatively (e.g. 0, 100, 1000, 300, 1000, 300 for 3 vibrations and so on..) but remember @Dave's word use it responsibly. :)
Also note here that the repeat parameter is set to -1 which means the vibration will happen exactly as mentioned in the pattern. :)