Vibration in Android

person Jason Huangfolder_openAndroid, Codelocal_offer, , access_time September 8, 2010

This code vibrates the phone for 1000 milliseconds. After getting the vibrator service with Context.getSystemService we call Vibrator.vibrate for a given time in milliseconds.


This vibration requires vibrate permission in Manifest to run.

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);

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>