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?
Related
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?
How do I play a sound simultaneously with the camera shutter going off?
In my application, I have an inset camera preview. It takes 3 pictures automatically after 5 seconds of the activity starting. During this time the application is receiving a range of values via Bluetooth. Everytime the values are greater than a preset threshold, the application plays a tone, which is done using MediaPlayer.
The problem is that when the camera goes off, the shutter click sound seems to take over all the audio, and the tone being played stops and only resumes after the 3 shutter clicks. I don't want to silence the camera shutter, so is there a way I can get the tone to play with shutter clicks? This is all happening in one activity.
Thanks
One possible solution would be to use the hidden ENFORCED_AUDIBLE stream type for your tones. This is the stream type that the camera shutter sound most likely will use, so it won't be muted unless the shutter sound has been muted.
Note that this stream type wasn't introduced until ICS (or maybe it was GB/HC, I can't say for sure off the top of my head), so it won't be compatible with every version of Android in existence. The integer value for this stream type identifier is 7, but if you want to check if exists / get its value programmatically you might be able to do so using reflection on the AudioSystem class.
Here's an example of how this could be done:
public static boolean mHasEnforcedStream = true;
public static int STREAM_SYSTEM_ENFORCED = 0;
...
static
{
try
{
Class asClass = Class.forName("android.media.AudioSystem");
Field sseField = asClass.getDeclaredField("STREAM_SYSTEM_ENFORCED");
STREAM_SYSTEM_ENFORCED = sseField.getInt(null);
}
catch (Exception e)
{
mHasEnforcedStream = false;
}
}
Keep in mind that if you use this stream type you'll always get your tones in the loudspeaker even if the user has e.g. a 3.5mm wired headset attached, and even if the user has put his/her phone in silent mode.
I think this is what you should need. This should contain what you need. The first link is probably more useful than the 2nd since you want to still have other sounds, though its possible you'd be able to disable the audio channel specific to the camera shuttle sounds.
Is there any way to replace or silence the camera shutter sound in android?
stop camera click sound programmatically in android
Well since I am still new to programming, I would do a google search on what files give off the camera sound, and I would put in your app to where it would rename those files with different extension so the sound would not go off and have them rename back to the original files. OR I would look on how to make the camera silent through changing the camera values. I know on my Samsung Galaxy SIII I had to change the camera file names. (sprint carrier)
I was trying to make an Android APP whose main function is to detect
if other android APPs are recording voice using Microphone. So far, I learned
that getRecordingState() from AudioRecord class can be used to get the state
of whether microphone is recording or not... but I need something like a broadcast
so I can catch the intent while the state of microphone starts to record voice...
any idea ? Thanks in advance!!
getRecordingState() returns the state for the particular AudioRecord instance that you call the method on. It doesn't give you some global state for all recorders.
There's currently no API available for applications to check globally whether there's ongoing recording from the microphone. The AudioFlinger has that information (though not about which specific application that is doing the recording), but the only way for you to get hold of it would be to modify Android itself and run your own custom Android version.
Try AudioManager.isMicrophoneMute()
http://developer.android.com/reference/android/media/AudioManager.html#isMicrophoneMute()
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.
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.