Reputation: 67
I disabled the camera shutter sound like this:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
mgr.setStreamVolume(AudioManager.STREAM_SYSTEM,0,0);
mgr.adjustStreamVolume(AudioManager.STREAM_SYSTEM,AudioManager.ADJUST_MUTE, 0);
} else {
mgr.setStreamMute(AudioManager.STREAM_SYSTEM, true);
}
This works great for most of my testdevices.
If my systemwide soundoptions are on loud, i can disable and enable the shutter sound in my apps settings.
I testet on a Samsung A3(2016) and a Samsung S7 as well and the shutter sound is always on maximum. When I totally mute all the sounds in my systemsettings outside the application - still, the shutter sound is there. Also if I disable the shutter sound with the code snippet from above inside the app, on Samsung devices the shutter sound is played.
I tried to mute all flags:
int streams = AudioManager.STREAM_ALARM|
AudioManager.STREAM_DTMF|
AudioManager.STREAM_MUSIC|
AudioManager.STREAM_NOTIFICATION|
AudioManager.STREAM_RING|
AudioManager.STREAM_SYSTEM|
AudioManager.STREAM_VOICE_CALL;
mgr.adjustVolume(AudioManager.ADJUST_MUTE, streams);
Still the same result.
Can anyone tell me, what I'm missing here? Is Samsung using some sort of different Audiostream?
EDIT 1: I added the following code in order to check if the code snippet from above is changing anything:
int streamMuted = mgr.getStreamVolume(AudioManager.STREAM_SYSTEM);
mgr.setStreamMute(AudioManager.STREAM_SYSTEM, true);
Boolean volumeFixed = mgr.isVolumeFixed();
streamMuted = mgr.getStreamVolume(AudioManager.STREAM_SYSTEM);
The output here is that the STREAM_SYSTEM has the StreamVolume '6' in the beginning, then I'm Muting this Stream. After that I'm checking if the device implements a fixed volume policy, which is 'false'. After checking the StreamVolume again, it has the value '0'.
So can it be that the shutter sound has a completely different AudioStream, even when I use the default system camera, the shutter sound can be disabled by muting the System Sound Settings?
Upvotes: 0
Views: 1811
Reputation: 2706
Shutter sound could be hardware/manufacturer dependant. In some Android versions/ROM the shutter sound cannot be disabled. You could try to enable the "DoNotDisturb" mode just before take the photo, but it's not guaranteed to work well.
Update
There could be three other solutions to try just before take the photo:
Upvotes: 1
Reputation: 1723
put this into your manifest
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
Upvotes: 1