title: Android: How to Toggle Between Vibrate Settings (Always, Never, Only in Silent Mode, Only When Not in Silent Mode)? Revisited
body: <p><strong>Issue</strong></p>
  
  <p>Finding methods to toggle between: </p>
  
  <ul>
  <li>Always </li>
  <li>Never</li>
  <li>Only in Silent Mode </li>
  <li>Only When Not in Silent Mode</li>
  </ul>
  
  <p>These choices are found by the path --- Menu >> Settings >> Sound >> Vibrate --- on the phone.</p>
  
  <p>It is simple to change by navigation on the phone (by the way, my phone is a Motorola Atrix 2 with Android 2.3.3), but I have yet to come across methods to use in my code.</p>
  
  <p><strong>Code</strong></p>
  
  <p>I basically have buttons that should manipulate the vibrate settings when clicked.  One of these buttons is shown here:</p>
  
  <pre><code>    bSilent.setOnClickListener(new View.OnClickListener() 
      {
          public void onClick(View v) 
          {
              audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
              audioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_OFF);
              audioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION, AudioManager.VIBRATE_SETTING_OFF);
  
              Toast.makeText(getBaseContext(), "Set to Never", Toast.LENGTH_SHORT).show();
          }
      });
  </code></pre>
  
  <p>audioManager is defined somewhere above this code as:</p>
  
  <pre><code>final AudioManager audioManager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
  </code></pre>
  
  <p>Android offers the AudioManager.setVibrateSetting, but it is now deprecated.  Instead, they reference you to the getRingerMode method.</p>
  
  <p><a href="http://developer.android.com/reference/android/media/AudioManager.html" rel="nofollow noreferrer">http://developer.android.com/reference/android/media/AudioManager.html</a></p>
  
  <p>However, using these functions (and any combination of them) do not efficiently move between the four vibrate settings.  For example, if I start at "Always", it is seemingly impossible for me to get to "Never".  All combinations of vibrate methods will only move between "Always" and "Only in Silent Mode".  On the other hand, if I start at "Never", the offered methods will only toggle between "Never" and "Only When Not in Silent Mode".</p>
  
  <p>Therefore, suppose I want to have my phone in silent mode and want it to vibrate.  Then, I decide I do not wish it to vibrate any longer.  I am unable to switch from "Always" or "Only in Silent Mode" to "Never".</p>
  
  <p><strong>Past Solutions and Posts</strong></p>
  
  <p>I am aware that this is somewhat of a duplicate post on StackOverflow.  The issue has been brought up before...</p>
  
  <p>Here: <a href="https://stackoverflow.com/questions/3742323/vibrate-settings-on-android-2-2">Vibrate settings on Android 2.2</a></p>
  
  <p>And (more recently) here: <a href="https://stackoverflow.com/questions/11264550/changing-vibrate-setting">Changing vibrate setting</a></p>
  
  <p>The former of the links provides an "answer".  LuTHieR ends up in a discussion and eventually figures out a way on his own.  He references the site:</p>
  
  <p><a href="https://android.googlesource.com/platform/packages/apps/Settings/+/froyo-release/src/com/android/settings/SoundSettings.java" rel="nofollow noreferrer">https://android.googlesource.com/platform/packages/apps/Settings/+/froyo-release/src/com/android/settings/SoundSettings.java</a></p>
  
  <p>and says "I looked at the source code of the com.android.settings.Settings class and copied part of the methods that enable and disable vibrate".</p>
  
  <p>I looked through this site vigorously and could not find what he did.  Could anyone clarify his solution?</p>
  
  <p><strong>Question</strong></p>
  
  <p>Does anyone have a way to precisely toggle between "Always", "Never", "Only in Silent Mode", and "Only When Not in Silent Mode"?</p>