2

My Application still plays the sounds when My Phone is on silent.

I think it is because I am using media Player.

    MediaPlayer mAlarmPlayer = MediaPlayer.create(ConnectingActivity.this, R.raw.echo_affirm1);
    mAlarmPlayer.start();

What Alternative am I meant to be using which forces it to comply with the phones current audio state?

In other words what I am looking for, Is the app must not make a sound when the phone is on silent. And if the phone is in normal mode then my tones can be played.

Zapnologica
  • 22,170
  • 44
  • 158
  • 253
  • possible duplicate of [how can I detect whether the android phone in Silent mode programatically](http://stackoverflow.com/questions/2048427/how-can-i-detect-whether-the-android-phone-in-silent-mode-programatically) – Nachi Jul 29 '14 at 14:18
  • 1
    @Nachi - that's certainly worth reading as supporting material, but I don't think it's a duplicate of the question asked here. – Chris Stratton Jul 29 '14 at 14:30
  • 1
    I tend to agree with @Nachi, As I am more looking for a solution that I say play this audio file, and it will look at the phones state, and decide whether to play it aloud or not. – Zapnologica Jul 30 '14 at 06:09

1 Answers1

2

Try with this:

Call this API in your onCreate():

setVolumeControlStream(AudioManager.STREAM_MUSIC);

This tells the AudioManager that when your application has focus, the volume keys should adjust music volume.

You have here the documentation.

Edit:

About playing the sound even if it is on silent mode, the silent mode checkbox says the following:

Silence all sounds except media & alarms.

So I suppose that you are trying to play an alarm, and that's why it plays it even if you are in silent mode.

Yo could try using this:

if (audioManager.getRingerMode() == AudioManager.RINGER_MODE_NORMAL) {
    // Play the sound
}
masmic
  • 3,526
  • 11
  • 52
  • 105