I am an Android Developer

Friday, July 16, 2010

Android: Vibrate the phone for a given time or a certain pattern

Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);

// 1. Vibrate for 1000 milliseconds
long milliseconds = 1000;
v.vibrate(milliseconds);

// 2. Vibrate in a Pattern with 500ms on, 500ms off for 5 times
long[] pattern = { 500, 300 };
v.vibrate(pattern, 5);

For this to work, you will have to add the android.permission.VIBRATE permission to your Manifest.xml

No comments:

Post a Comment