title: How to enable and disable vibration mode programmatically
body: <p>I need to enable and disable the vibration mode of mobile when user turns off and turns on the switch button .</p>
  
  <p>I have tried the code below, but it's not working:  </p>
  
  <pre><code>AudioManager myAudioManager;
  myAudioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
  
  Toast.makeText(this, "in setting "+(myAudioManager.getMode()==AudioManager.RINGER_MODE_VIBRATE),1).show();
  
  if(myAudioManager.getMode()==AudioManager.RINGER_MODE_VIBRATE) {
      //myAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
      myAudioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_OFF);
  }
  else
  {
      //myAudioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
      myAudioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_ON);
  }
  </code></pre>