title: Troubles play sound in silent mode on Android
body: <p>I am writing an android application to simply play an alarm no mater what mode the phone even if it is in silent mode.</p>
  
  <p>I found this <a href="https://stackoverflow.com/questions/4071149/override-silent-mode-and-or-media-volume">question</a> and used the code from the answer to override the current volume state. My code looks like this:</p>
  
  <pre><code>Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
      if (alert == null){
          // alert is null, using backup
          alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
          if (alert == null){
              // alert backup is null, using 2nd backup
              alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
      }
  }
  ringtone = RingtoneManager.getRingtone(getApplicationContext(), alert);
  
  AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
  int volume = audioManager.getStreamVolume(AudioManager.STREAM_ALARM);
  if(volume == 0){
      volume = audioManager.getStreamMaxVolume(AudioManager.STREAM_ALARM);
  }
  audioManager.setStreamVolume(AudioManager.STREAM_ALARM, volume,AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
  
  if(ringtone != null){
      ringtone.play();
  }
  </code></pre>
  
  <p>By debugging it seems that my problem start in this line:</p>
  
  <pre><code>int volume = audioManager.getStreamVolume(AudioManager.STREAM_ALARM);
  </code></pre>
  
  <p>since my phone seems to return 4 when it is in silent mode and 7 when it is at max volume. I do not know if this is, what it is supposed to return. I just supposed that if the phone is in silent mode it would return 0.</p>
  
  <p>Anyone who can point me in the right direction?</p>