How To Vibrate The Android PhoneHow To Vibrate The Android Phone

Vibrate The Android Phone in android program

Answer 1

To vibrate a phone we need following Permission Do not forget to declare this permission in Manifest.
   

Code for vibration :
   
   Vibrator v = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);

   // pass the number of millseconds fro which you want to vibrate the phone here we
   // have passed 2000 so phone will vibrate for 2 seconds.

   v.vibrate(2000); 

Answer 2

Always try to call vibration inside thread or use as separate service.
  
  Thread vibrateThread= new Thread(new Runnable() {
    public void run() {
	try {
             Vibrator v = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);

             // pass the number of millseconds fro which you want to vibrate the phone here we
            // have passed 2000 so phone will vibrate for 2 seconds.

            v.vibrate(2000); 
        } 
       catch (Throwable t) {
	   Log.i("Vibration", "Thread  exception "+t);
	}	
       }
   });
  
   vibrateThread.start();
 

SUBMIT YOUR ANSWER

  |  
 
 
 

Preview :