Android Vibrate on touch?

I am trying to make my device vibrate when I touch an object on Screen. I am using this code:

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

with the permission in the manifest file but I don’t seem to get any results.
Any suggestions? Also, my hardware supports vibrate.

  • Unable to resolve target 'android-21'
  • How to change text color of simple list item
  • Gmail API access using Android
  • Getting the size of the window WITHOUT title/notification bars
  • Trouble getting Android Support V7 CardView Library to work
  • Continuous Integration for Android via TeamCity. Preferred tools?
  • Related posts:

    Filter LogCat to get only the messages from My Application in Android?
    Android emulator system partition no space from start
    How to identify three finger tap in android
    Can't find getPackageManager() method in android
    Facebook Android SDK Invalid_key
    How to use setOnTouchListener in C# (Xamarin)
  • What is the role of content_main.xml in android studio 1.4?
  • IllegalStateException: Activity has been destroyed - when app is trying to show DialogFragment once more time
  • Media Recorder with Google Vision API
  • e.printStackTrace(); in string
  • How to create layout-small-land folder?
  • Android: How to use selector for background of a TextView?
  • 3 Solutions collect form web for “Android Vibrate on touch?”

    please try this :

    Button b = (Button) findViewById(;
        b.setOnTouchListener(new OnTouchListener() {
            public boolean onTouch(View v, MotionEvent event) {
                // TODO Auto-generated method stub
                Vibrator vb = (Vibrator)   getSystemService(Context.VIBRATOR_SERVICE);
                return false;

    and add this permission to manifest.xml

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

    According to this answer, you can perform haptic feedback (vibrate) without asking for any extra permissions. Look at performHapticFeedback method.

    View view = findViewById(...)

    Note: I have not tested this code.

    This will vibrate once, when user touched view (will not keep vibrating when user still moves his finger!):

    public boolean onTouch(View view, MotionEvent event) {
        if(event.getAction() == MotionEvent.ACTION_DOWN) {
            Vibrator v = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
        return true;

    And as Ramesh said, allow permission in manifest:

    <uses-permission android:name="android.permission.VIBRATE"/>
    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.