3

I've looked everywhere I can think of to find an answer to this, and there are LOTS of questions about the audio in Android, but none that I can find that talk about the new settings in ICS.

My app has a feature where the users can press a button and the phone's ringer will be silent, along with no vibration. Here is my code, which up until now has worked fine:

        mAudioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_OFF);
        mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
        mAudioManager.setStreamVolume(AudioManager.STREAM_RING, 0, 0);

Now what happens is that when the user presses the button, the volume goes to 0 still, but the phone, specifically the Galaxy S3, has a short vibrate. Then in Settings->Sound, Silent Mode has been changed from Off to Vibrate. So whenever certain things happen, it still has that short vibrate notification. I haven't been able to test thoroughly enough to know what specifically happens in order for it to vibrate like that, but that's not the point of the question.

My question is how can we control the ICS Silent Mode settings of Off, Vibrate, and Mute? I want to be able to set it to Mute when they hit that button, and then go back to Off, or whatever they had it set to, when they hit it again. I tried using the mAudioManager.setStreamMute method, but this is not the desired effect, and it also doesn't change the setting of Silent Mode.

Thanks in advance for any help, it's much appreciated!!

Paul

zpert
  • 706
  • 9
  • 18
  • 2
    `mAudioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);` will set the Silent mode. I think that line will do the job. – iTurki Sep 01 '12 at 18:48
  • 1
    I deleted my comment that it didn't work, because other factors seemed to be involved! I think it does in fact work, but I'll leave another comment when I know for sure. I'm going to simplify my code so I can easily check, since it is doing to much to be sure right now of that one setting. Thanks so much!! – zpert Sep 02 '12 at 16:22

1 Answers1

4

OK I figured it out!!!! +1 to iturki for the help, thanks!! I had tried the RINGER_MODE_SILENT already, but didn't think it worked. It didn't work, but that's because it was only half the solution. It is needed though!

Here's the way it is working for me every time:

I found that with either setting AudioManager.RINGER_MODE_NORMAL or AudioManager.RINGER_MODE_SILENT, I was still receiving the vibrations for notifications. This is why I commented that it didn't work. After further testing, I found that it is not the RINGER_MODE setting that is causing this, it is in fact this line of code:

mAudioManager.setStreamVolume(AudioManager.STREAM_RING, 0, 0);

For some reason unknown to me, with either RINGER_MODE setting of NORMAL or SILENT, when the STREAM_RING volume is set to 0 in this way, it changes the Silent Mode setting in Settings->Sound to Vibrate.

The SOLUTION:

    mAudioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_OFF);
    mAudioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);

I had to remove the STREAM_RING setting and just leave it alone. Now, when I set it to RINGER_MODE_SILENT and leave the STREAM_RING alone, no more annoying half second vibrations!!! One extra note, I tested without setting the VibrateSetting to OFF, and it still worked, but I'm leaving it for other reasons in my app.

IMPORTANT: I don't know how this change from RINGER_MODE_NORMAL to RINGER_MODE_SILENT will affect previous versions of Android, so be careful. If anyone knows for sure what this change would affect on previous versions, please feel free to let us know!

Thanks again iturki for the help!

zpert
  • 706
  • 9
  • 18
  • 1
    Hard to find this solution but this was exactly what I looked for. This code is working on previous version of Android too - I checked with 2.3.5. – Remi Mar 03 '14 at 08:07