beware_bear
beware_bear

Reputation: 67

Disable Camera Shutter Sound, AudioManager not working in Samsung

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

Answers (2)

emandt
emandt

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:

  • mute the hidden "AudioManager.STREAM_SYSTEM_ENFORCED" streamType (using Reflection)
  • set "AudioManager.setSpeakerphoneOn(false)"
  • temporarily disable the Speaker using the hidden "android.media.AudioSystem.setDeviceConnectionState()" (pay attention that this procedure will set the Speaker OFF for ALL ANDROID SYSTEM so it's very dangerous if not well managed and then not well restored to the previous value when done)

Upvotes: 1

Nirav Joshi
Nirav Joshi

Reputation: 1723

put this into your manifest

  <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />

Upvotes: 1

Related Questions