Make Your Android Phone Vibrate

So I got this good suggestion from one user’s comment: when shake to shuffle, make the phone vibrate.

It’s actually a very simple 2-step operation, but android developer site wasn’t very clear about. Here’s how I did it:

  1. Add permission in AndroidManifest.xml file like this:
    <manifest xmlns:android="http://schemas.android.com/apk/res/android">
    	<uses-permission android:name="android.permission.VIBRATE" />
    ......
    </manifest>
  2. In your program when you want the phone to vibrate:
    // vibration lasts 300 milliseconds
    ((Vibrator)getSystemService(VIBRATOR_SERVICE)).vibrate(300);

Done!

 
Add a comment

Comments (9)

  1. lokinou, November 18, 2011
    Super, add a line to manifest, add a line to main, pack in apk file, upload to phone, install, use. 5 min chrono, and everybody in office now think that i'm willing to make a sex toy with my mobile phone.... Reply
  2. gibffe, April 4, 2011
    wikid, works perfectly for me ! Reply
  3. arti, February 7, 2010
    sorry!! it actually does!!! thanks a lot! i was searching for that for ages! Reply
  4. arti, February 7, 2010
    doesnt work for me.. dev 1 Reply
  5. Jesse, January 19, 2010
    Awesome, notification.vibrate was overkill for me - this one is cool :) Reply
  6. Mike, October 29, 2009
    Perfect! Took me 20 minutes to find how to do what should be a simple, standard task. Thanks for posting this! Reply
  7. Batchuluun, October 20, 2009
    its working thanks Reply
  8. yuchen, August 22, 2009
    I think you have to define the service first. Reply
  9. Ramesh, August 12, 2009
    I am getting "VIBRATE_SERVICE cant be resolved error" in 1.5 Sdk Reply

Add a comment

Top
(it will not be shared)