Android Vibrator pattern explained

  • Posted on: 29 February 2016
  • By: robin
Android Vibrator pattern explained

The Android Vibrator feature is supported by the majority of the android devices. It is easy to understand. First of all the feature requires premissions. So first thing you need to do is edit your AndroidManifest.xml:

<uses-permission android:name="android.permission.VIBRATE"/>

Next: The Vibrator service.

 Vibrator vibrator = (Vibrator) this.context.getSystemService(Context.VIBRATOR_SERVICE);
Now you need to define a pattern how the Vibrator should vibrate. The explaination in the Android documentation for Vibrator is:

"The first value indicates the number of milliseconds to wait before turning the vibrator on. The next value indicates the number of milliseconds for which to keep the vibrator on before turning it off. Subsequent values alternate between durations in milliseconds to turn the vibrator off or to turn the vibrator on."

Practical this should can look like this:

long[] pattern = {
        0,  // 0 milliseconds delay
        30, // 30 milliseconds vibrate
        1000, // 1000 milliseconds pause
        1, // 1 millisecond vibrate
        1, // 1 millisecond pause
        10, // 10 milliseconds vibrate

The last step is starting the vibration.

vibrator.vibrate(pattern, -1); //-1 = do not repeat
Thats it. Have fun with your vibrating Android phone.
android, howto, how to, vibrator, tutorial, development