Android setStreamVolume to ZERO doesn't work in Android 4 - android

I noticed that under Android 4.x setting ring volume to 0 is not possible. If I execute this code and then I go to Settings--> Sound --> Volumes I can see it is set to 1. I
audiomanager.setStreamVolume(AudioManager.STREAM_RING, 0, 0);
Do you know why?
I know I could use audiomanager.setRingerMode(RINGER_MODE_SILENT) but annoys me!! because in this case I would have to "remember" if vibration is on or off for activating again sound.
Of course, all this works in other Android versions.

Don't use setStreamMute() as it has weird side-effects with the lifecycle of your process. See the docs:
The mute command is protected against client process death: if a process with an active mute request on a stream dies, this stream will be unmuted automatically.
I'm afraid setRingerMode() with either RINGER_SILENT or RINGER_VIBRATE is the way to go, which will have the effect of zero-ing out the stream volume

try setStreamMute instead which is equivalent to setting volume to 0.

Related

How to silence incoming call or notification on Android Pie?

My code used to successfully silence incoming calls by simply using setRingerMode, but ever since Android Pie, it's just not working anymore. I had tested the built-in DND mode, and it seemed to not be working either. But if that's true, it's working now, but my code still isn't.
Is there something additional necessary for this to work now? Android Pie does keep a separate mode from DND for ring, vibrate, and silence for ringer sounds, but I haven't been able to find figure out why my code isn't working anymore.
Update:
I'm using the following code:
AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
am.setRingerMode(AudioManager.RINGER_MODE_SILENT);
Update (1-23-19):
My understanding is I can't change the notification channel of another app, like the texting or calling app. Does anybody know any differently?

Programmatically muting a call in Android

I am revisiting an old question posted (in early 2014 mind) here:
What permissions are needed to programmatically mute a phone call, from a background app?
How to Mute Phone Call Stream (uplink) while calling on Android
How to mute audio speaker in android
How does setMicrophoneMute() work?
For a recent project, I am building an app that can mute an existing call and get an audio recording from the user. I know that audio-recording in-call works, that's no problem (recording only the user mic). Now i can also reduce the volume programmatically, which i did using the code On my Github, Here
Specifically, I am using the AudioManager class to set the volume to 0 and also muting as a backup, but doesn't work.. I am wondering whether this is a Samsung specific issue or not..
mgr.setStreamVolume(stream, progress, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
mgr.adjustVolume(AudioManager.ADJUST_MUTE, AudioManager.FLAG_VIBRATE);
boolean a = mgr.isVolumeFixed();
Log.d("MUTING", "Volume fixed: "+a);
boolean streamMuteStatus = mgr.isStreamMute(stream);
Log.d("MUTING", "Stream Mute Status: "+streamMuteStatus);
I am printing out the boolean variables above for testing purposes, but both print out 'False'.
But the Samsung S5 device is not allowing me to set the volume to 0 at all. This is true even when adjusting the in-call volume using the volume slider.. The slider does not physically move to the leftmost position on the seekbar. See figure below for the leftmost position i can drag to:
Anyone have any ideas about how i can mute the incoming call stream?

How to handle failed AudioFocus requests in Android?

I am working on an application that has media playing features.
I would like to honor AudioFocus. I first request AudiFocus:
audioManager.requestAudioFocus(new CustomOnAudioFocusChangeListener(), AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
This call returns either AUDIOFOCUS_REQUEST_FAILED or AUDIOFOCUS_REQUEST_GRANTED.
I guess I shouldn't start playback if I receive AUDIOFOCUS_REQUEST_FAILED. But then what to do?
Will my CustomOnAudioFocusChangeListener be notified when focus becomes available or is it only when you got AUTOFOCUS_REQUEST_GRANTED that it starts getting updates?
Should I inform the user and ask him to try again later? Or retry programmatically after some time?
Thanks in advance
What to do depends on how you want your app to react. You shouldn't start playing, you may want to message your user. Or if its something non-critical, you may silently ignore the failure and move on.
I believe you only get updates on the listener on success. You get the updates then so if you're lowered you can choose to duck your output or pause until you regain.

Set maximum audio level, don't need alert message

I have an audio app which will drive an external audio amplifier. In the code I set the maximum audio level:
int maxAudioVolume = audioManager.getStreamMaxVolume(AudioManager.STREA M_MUSIC);
audioManager.setStreamVolume(AudioManager.STREAM_M USIC,maxAudioVolume,0);
If I plug in the amplifier, then always the following alert is issued:
Raise volume above recommended level?
This is becoming irritating. Does anybody know how the alert can be avoided? Actually, this issue has been addressed in other forums, and sometimes it was solved, but always by using some app. Thus it should be possible, but the question is: how?
Wouter Boeke
See this:
Disable sound safe level notification in android & xda-developers; Unsafe Volume - disable safe media volume popup/check
Basically you need to root your phone, and set config_safe_media_volume_enabled at boot time to false. Which happens I think if the user clicks ok, you can't get rid of it without root.

AudioManager - difference between two methods

What is the difference between calling AudioManager.setRingerMode to calling AudioManager.setStreamMute(AudioManager.STREAM_VOICE_CALL, ...)
What does the documentation mean by "Ringer mode"? I'm pretty sure it is the phone ringer mode. Then how does it differ from calling setStreamMute with STREAM_VOICE_CALL?
If it is not the phone ringer mode, then what is it?
Thanks in advance.
I have never used the audio stream on the android platform, however, based on reading the documentation, I think setRingerMode will affect how the phone reacts to incoming calls. For example, AudioManager.setRingerMode(RINGER_MODE_SILENT) will disable vibrations and sound when an incoming call is received.
However, AudioManager.setStreamMute seems to control more than just the audio stream for phone rings.
From the documentation at http://developer.android.com/reference/android/media/AudioManager.html#STREAM_VOICE_CALL
I think that AudioManager.setRingerMode(RINGER_MODE_SILENT) will act the same way as AudioManager.setStreamMute(STREAM_RING, true).
I think the best way to see what the difference is (nd to see if what I am saying is true) would be to write a small program that tests the two features.

Categories

Resources