android mute camera shutter sound?
I am using this
camera.takePicture(null, rawCallback, jpegCallback);
but with some devices it makes a sound when the camera captures the image.
Please can any one help, how can I mute camera shutter sound?
android android-camera
add a comment |
I am using this
camera.takePicture(null, rawCallback, jpegCallback);
but with some devices it makes a sound when the camera captures the image.
Please can any one help, how can I mute camera shutter sound?
android android-camera
I think this is somewhat undoable. At least in The States it was enforced by legislation to have all camera devices make a shutter sound. This is the case in some other countries too AFAIK.
– harism
Jan 23 '13 at 10:02
harism in some device it cause problem i had tested in nexus,s2,nexus table all device capture silently but htc desicer and some device cause problem.
– PankajAndroid
Jan 23 '13 at 10:15
is feeding the method with a silenced sound file a doable idea?
– dumbfingers
Jan 23 '13 at 10:29
add a comment |
I am using this
camera.takePicture(null, rawCallback, jpegCallback);
but with some devices it makes a sound when the camera captures the image.
Please can any one help, how can I mute camera shutter sound?
android android-camera
I am using this
camera.takePicture(null, rawCallback, jpegCallback);
but with some devices it makes a sound when the camera captures the image.
Please can any one help, how can I mute camera shutter sound?
android android-camera
android android-camera
edited Jan 23 '13 at 10:01
Mark Davidson
4,77452953
4,77452953
asked Jan 23 '13 at 9:55
PankajAndroid
1,74832140
1,74832140
I think this is somewhat undoable. At least in The States it was enforced by legislation to have all camera devices make a shutter sound. This is the case in some other countries too AFAIK.
– harism
Jan 23 '13 at 10:02
harism in some device it cause problem i had tested in nexus,s2,nexus table all device capture silently but htc desicer and some device cause problem.
– PankajAndroid
Jan 23 '13 at 10:15
is feeding the method with a silenced sound file a doable idea?
– dumbfingers
Jan 23 '13 at 10:29
add a comment |
I think this is somewhat undoable. At least in The States it was enforced by legislation to have all camera devices make a shutter sound. This is the case in some other countries too AFAIK.
– harism
Jan 23 '13 at 10:02
harism in some device it cause problem i had tested in nexus,s2,nexus table all device capture silently but htc desicer and some device cause problem.
– PankajAndroid
Jan 23 '13 at 10:15
is feeding the method with a silenced sound file a doable idea?
– dumbfingers
Jan 23 '13 at 10:29
I think this is somewhat undoable. At least in The States it was enforced by legislation to have all camera devices make a shutter sound. This is the case in some other countries too AFAIK.
– harism
Jan 23 '13 at 10:02
I think this is somewhat undoable. At least in The States it was enforced by legislation to have all camera devices make a shutter sound. This is the case in some other countries too AFAIK.
– harism
Jan 23 '13 at 10:02
harism in some device it cause problem i had tested in nexus,s2,nexus table all device capture silently but htc desicer and some device cause problem.
– PankajAndroid
Jan 23 '13 at 10:15
harism in some device it cause problem i had tested in nexus,s2,nexus table all device capture silently but htc desicer and some device cause problem.
– PankajAndroid
Jan 23 '13 at 10:15
is feeding the method with a silenced sound file a doable idea?
– dumbfingers
Jan 23 '13 at 10:29
is feeding the method with a silenced sound file a doable idea?
– dumbfingers
Jan 23 '13 at 10:29
add a comment |
5 Answers
5
active
oldest
votes
You can turn it off programmatically from 4.2 onwards with:
Camera.CameraInfo info = new Camera.CameraInfo();
Camera.getCameraInfo(id, info);
if (info.canDisableShutterSound) {
mCamera.enableShutterSound(false);
}
you right @Jono but on above 4.2 verion it' nothing of use
– PankajAndroid
Feb 25 '13 at 10:13
add a comment |
To mute, put this code before capturing an image
AudioManager mgr = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
mgr.setStreamMute(AudioManager.STREAM_SYSTEM, true);
camera.takePicture(null, rawCallback, jpegCallback);
After 1 second it will unmute by putting in the below code:
final Handler handler = new Handler();
Timer t = new Timer();
t.schedule(new TimerTask() {
public void run() {
handler.post(new Runnable() {
public void run() {
AudioManager mgr = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
mgr.setStreamMute(AudioManager.STREAM_SYSTEM, false);
}
});
}
}, 1000);
1
why use a timer when you can call postDelayed on the handler?
– Alessandro Roaro
May 24 '14 at 9:44
add a comment |
Use Below two lines before button click
AudioManager mgr = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
mgr.setStreamMute(AudioManager.STREAM_SYSTEM, true);
And these two lones just after image get captured:
AudioManager mgr = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
mgr.setStreamMute(AudioManager.STREAM_SYSTEM, false);
I know only this solution and I personally used it in my application
Thanks it work but for unmute after 1second so it will not sound while capturing.
– PankajAndroid
Jan 23 '13 at 10:30
add a comment |
As harism mentioned, this is not possible to do on some devices, because there are legal requirements in some markets (Japan, for example) that taking a picture always results in an audible shutter sound.
The stream type used for these types of sounds is STREAM_SYSTEM_ENFORCED
, and there's a read-only system property that determines whether or not you can mute such a stream.
Thanks micheal and harism it's solve by this way for mute: AudioManager mgr =(AudioManager)context.getSystemService(context.AUDIO_SERVICE); mgr.setStreamMute(AudioManager.STREAM_SYSTEM, true); for unmute: final Handler handler = new Handler(); Timer t = new Timer(); t.schedule(new TimerTask() { public void run() { handler.post(new Runnable() { public void run() { AudioManager mgr = (AudioManager)context.getSystemService(context.AUDIO_SERVICE); mgr.setStreamMute(AudioManager.STREAM_SYSTEM, false); } }); } }, 1000);
– PankajAndroid
Jan 23 '13 at 10:28
@PankajJolapara you can post your own solution as an answer and accept the answer that solves your problem. This could help anyone who has the same problem. :)
– dumbfingers
Jan 23 '13 at 10:31
There are devices for which the proposed solution won't work, since they're set to always route the shutter sound to the loudspeaker and not allow it to be muted. Again, it depends largely on the market where the device was sold.
– Michael
Jan 23 '13 at 10:41
add a comment |
Well, all those solutions are good but i prefer setting the volume to 0 (and not only system since some devices users other streams then system and/or not all streams include system) before:
smth like this would work flawlessly:
Camera mCamera = null;
function takePicture() {
storeSoundSettings();
setMuteAll(true);
// init camera and such.
Camera.CameraInfo info = new Camera.CameraInfo();
Camera.getCameraInfo(IdOfCameraBackOrFront, info);
if (info.canDisableShutterSound) {
camera.enableShutterSound(false);
}
setMuteAll(false);
recoverSoundSettings();
}
and store, recover and setMuteAll something like this:
int streams = new int{
AudioManager.STREAM_ALARM,
AudioManager.STREAM_DTMF,
AudioManager.STREAM_MUSIC,
AudioManager.STREAM_NOTIFICATION,
AudioManager.STREAM_RING,
AudioManager.STREAM_SYSTEM,
AudioManager.STREAM_VOICE_CALL};
JSONObject json;
AudioManager manager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
public void storeSoundSettings() {
json = new JSONObject();
json.put("mode", manager.getMode());
json.put("ringermode", manager.getRingerMode());
for (int stream : streams) {
json.put("stream_" + stream, manager.getStreamVolume(stream));
}
}
public void recoverSoundSettings() {
json = new JSONObject(readString("last_audio_setting", null));
manager.setMode(json.getInt("mode"));
manager.setRingerMode(json.getInt("ringermode"));
for (int stream : streams) {
manager.setStreamVolume(stream, json.getInt("stream_" + stream), AudioManager.FLAG_ALLOW_RINGER_MODES);
}
public void setMuteAll(boolean mute) {
for (int stream : streams) {
manager.setStreamMute(stream, mute);
if (mute) {
manager.setStreamVolume(stream, 100, AudioManager.FLAG_ALLOW_RINGER_MODES);
} else {
manager.setStreamVolume(stream, 0, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
}
}
}
Do not forget to catch the exceptions. I removed them for better highlighting.
Are you miss with the setStreamVolume, it should be reversed
– Phuong
Aug 26 '16 at 14:02
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f14476791%2fandroid-mute-camera-shutter-sound%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can turn it off programmatically from 4.2 onwards with:
Camera.CameraInfo info = new Camera.CameraInfo();
Camera.getCameraInfo(id, info);
if (info.canDisableShutterSound) {
mCamera.enableShutterSound(false);
}
you right @Jono but on above 4.2 verion it' nothing of use
– PankajAndroid
Feb 25 '13 at 10:13
add a comment |
You can turn it off programmatically from 4.2 onwards with:
Camera.CameraInfo info = new Camera.CameraInfo();
Camera.getCameraInfo(id, info);
if (info.canDisableShutterSound) {
mCamera.enableShutterSound(false);
}
you right @Jono but on above 4.2 verion it' nothing of use
– PankajAndroid
Feb 25 '13 at 10:13
add a comment |
You can turn it off programmatically from 4.2 onwards with:
Camera.CameraInfo info = new Camera.CameraInfo();
Camera.getCameraInfo(id, info);
if (info.canDisableShutterSound) {
mCamera.enableShutterSound(false);
}
You can turn it off programmatically from 4.2 onwards with:
Camera.CameraInfo info = new Camera.CameraInfo();
Camera.getCameraInfo(id, info);
if (info.canDisableShutterSound) {
mCamera.enableShutterSound(false);
}
answered Feb 18 '13 at 12:52
Jono
4501615
4501615
you right @Jono but on above 4.2 verion it' nothing of use
– PankajAndroid
Feb 25 '13 at 10:13
add a comment |
you right @Jono but on above 4.2 verion it' nothing of use
– PankajAndroid
Feb 25 '13 at 10:13
you right @Jono but on above 4.2 verion it' nothing of use
– PankajAndroid
Feb 25 '13 at 10:13
you right @Jono but on above 4.2 verion it' nothing of use
– PankajAndroid
Feb 25 '13 at 10:13
add a comment |
To mute, put this code before capturing an image
AudioManager mgr = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
mgr.setStreamMute(AudioManager.STREAM_SYSTEM, true);
camera.takePicture(null, rawCallback, jpegCallback);
After 1 second it will unmute by putting in the below code:
final Handler handler = new Handler();
Timer t = new Timer();
t.schedule(new TimerTask() {
public void run() {
handler.post(new Runnable() {
public void run() {
AudioManager mgr = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
mgr.setStreamMute(AudioManager.STREAM_SYSTEM, false);
}
});
}
}, 1000);
1
why use a timer when you can call postDelayed on the handler?
– Alessandro Roaro
May 24 '14 at 9:44
add a comment |
To mute, put this code before capturing an image
AudioManager mgr = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
mgr.setStreamMute(AudioManager.STREAM_SYSTEM, true);
camera.takePicture(null, rawCallback, jpegCallback);
After 1 second it will unmute by putting in the below code:
final Handler handler = new Handler();
Timer t = new Timer();
t.schedule(new TimerTask() {
public void run() {
handler.post(new Runnable() {
public void run() {
AudioManager mgr = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
mgr.setStreamMute(AudioManager.STREAM_SYSTEM, false);
}
});
}
}, 1000);
1
why use a timer when you can call postDelayed on the handler?
– Alessandro Roaro
May 24 '14 at 9:44
add a comment |
To mute, put this code before capturing an image
AudioManager mgr = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
mgr.setStreamMute(AudioManager.STREAM_SYSTEM, true);
camera.takePicture(null, rawCallback, jpegCallback);
After 1 second it will unmute by putting in the below code:
final Handler handler = new Handler();
Timer t = new Timer();
t.schedule(new TimerTask() {
public void run() {
handler.post(new Runnable() {
public void run() {
AudioManager mgr = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
mgr.setStreamMute(AudioManager.STREAM_SYSTEM, false);
}
});
}
}, 1000);
To mute, put this code before capturing an image
AudioManager mgr = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
mgr.setStreamMute(AudioManager.STREAM_SYSTEM, true);
camera.takePicture(null, rawCallback, jpegCallback);
After 1 second it will unmute by putting in the below code:
final Handler handler = new Handler();
Timer t = new Timer();
t.schedule(new TimerTask() {
public void run() {
handler.post(new Runnable() {
public void run() {
AudioManager mgr = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
mgr.setStreamMute(AudioManager.STREAM_SYSTEM, false);
}
});
}
}, 1000);
edited Dec 28 '18 at 0:00
Killerrabbit
416
416
answered Jan 29 '13 at 11:07
CoronaPintu
1,32011320
1,32011320
1
why use a timer when you can call postDelayed on the handler?
– Alessandro Roaro
May 24 '14 at 9:44
add a comment |
1
why use a timer when you can call postDelayed on the handler?
– Alessandro Roaro
May 24 '14 at 9:44
1
1
why use a timer when you can call postDelayed on the handler?
– Alessandro Roaro
May 24 '14 at 9:44
why use a timer when you can call postDelayed on the handler?
– Alessandro Roaro
May 24 '14 at 9:44
add a comment |
Use Below two lines before button click
AudioManager mgr = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
mgr.setStreamMute(AudioManager.STREAM_SYSTEM, true);
And these two lones just after image get captured:
AudioManager mgr = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
mgr.setStreamMute(AudioManager.STREAM_SYSTEM, false);
I know only this solution and I personally used it in my application
Thanks it work but for unmute after 1second so it will not sound while capturing.
– PankajAndroid
Jan 23 '13 at 10:30
add a comment |
Use Below two lines before button click
AudioManager mgr = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
mgr.setStreamMute(AudioManager.STREAM_SYSTEM, true);
And these two lones just after image get captured:
AudioManager mgr = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
mgr.setStreamMute(AudioManager.STREAM_SYSTEM, false);
I know only this solution and I personally used it in my application
Thanks it work but for unmute after 1second so it will not sound while capturing.
– PankajAndroid
Jan 23 '13 at 10:30
add a comment |
Use Below two lines before button click
AudioManager mgr = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
mgr.setStreamMute(AudioManager.STREAM_SYSTEM, true);
And these two lones just after image get captured:
AudioManager mgr = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
mgr.setStreamMute(AudioManager.STREAM_SYSTEM, false);
I know only this solution and I personally used it in my application
Use Below two lines before button click
AudioManager mgr = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
mgr.setStreamMute(AudioManager.STREAM_SYSTEM, true);
And these two lones just after image get captured:
AudioManager mgr = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
mgr.setStreamMute(AudioManager.STREAM_SYSTEM, false);
I know only this solution and I personally used it in my application
answered Jan 23 '13 at 10:08
Ajit
4871423
4871423
Thanks it work but for unmute after 1second so it will not sound while capturing.
– PankajAndroid
Jan 23 '13 at 10:30
add a comment |
Thanks it work but for unmute after 1second so it will not sound while capturing.
– PankajAndroid
Jan 23 '13 at 10:30
Thanks it work but for unmute after 1second so it will not sound while capturing.
– PankajAndroid
Jan 23 '13 at 10:30
Thanks it work but for unmute after 1second so it will not sound while capturing.
– PankajAndroid
Jan 23 '13 at 10:30
add a comment |
As harism mentioned, this is not possible to do on some devices, because there are legal requirements in some markets (Japan, for example) that taking a picture always results in an audible shutter sound.
The stream type used for these types of sounds is STREAM_SYSTEM_ENFORCED
, and there's a read-only system property that determines whether or not you can mute such a stream.
Thanks micheal and harism it's solve by this way for mute: AudioManager mgr =(AudioManager)context.getSystemService(context.AUDIO_SERVICE); mgr.setStreamMute(AudioManager.STREAM_SYSTEM, true); for unmute: final Handler handler = new Handler(); Timer t = new Timer(); t.schedule(new TimerTask() { public void run() { handler.post(new Runnable() { public void run() { AudioManager mgr = (AudioManager)context.getSystemService(context.AUDIO_SERVICE); mgr.setStreamMute(AudioManager.STREAM_SYSTEM, false); } }); } }, 1000);
– PankajAndroid
Jan 23 '13 at 10:28
@PankajJolapara you can post your own solution as an answer and accept the answer that solves your problem. This could help anyone who has the same problem. :)
– dumbfingers
Jan 23 '13 at 10:31
There are devices for which the proposed solution won't work, since they're set to always route the shutter sound to the loudspeaker and not allow it to be muted. Again, it depends largely on the market where the device was sold.
– Michael
Jan 23 '13 at 10:41
add a comment |
As harism mentioned, this is not possible to do on some devices, because there are legal requirements in some markets (Japan, for example) that taking a picture always results in an audible shutter sound.
The stream type used for these types of sounds is STREAM_SYSTEM_ENFORCED
, and there's a read-only system property that determines whether or not you can mute such a stream.
Thanks micheal and harism it's solve by this way for mute: AudioManager mgr =(AudioManager)context.getSystemService(context.AUDIO_SERVICE); mgr.setStreamMute(AudioManager.STREAM_SYSTEM, true); for unmute: final Handler handler = new Handler(); Timer t = new Timer(); t.schedule(new TimerTask() { public void run() { handler.post(new Runnable() { public void run() { AudioManager mgr = (AudioManager)context.getSystemService(context.AUDIO_SERVICE); mgr.setStreamMute(AudioManager.STREAM_SYSTEM, false); } }); } }, 1000);
– PankajAndroid
Jan 23 '13 at 10:28
@PankajJolapara you can post your own solution as an answer and accept the answer that solves your problem. This could help anyone who has the same problem. :)
– dumbfingers
Jan 23 '13 at 10:31
There are devices for which the proposed solution won't work, since they're set to always route the shutter sound to the loudspeaker and not allow it to be muted. Again, it depends largely on the market where the device was sold.
– Michael
Jan 23 '13 at 10:41
add a comment |
As harism mentioned, this is not possible to do on some devices, because there are legal requirements in some markets (Japan, for example) that taking a picture always results in an audible shutter sound.
The stream type used for these types of sounds is STREAM_SYSTEM_ENFORCED
, and there's a read-only system property that determines whether or not you can mute such a stream.
As harism mentioned, this is not possible to do on some devices, because there are legal requirements in some markets (Japan, for example) that taking a picture always results in an audible shutter sound.
The stream type used for these types of sounds is STREAM_SYSTEM_ENFORCED
, and there's a read-only system property that determines whether or not you can mute such a stream.
answered Jan 23 '13 at 10:20
Michael
42.5k84292
42.5k84292
Thanks micheal and harism it's solve by this way for mute: AudioManager mgr =(AudioManager)context.getSystemService(context.AUDIO_SERVICE); mgr.setStreamMute(AudioManager.STREAM_SYSTEM, true); for unmute: final Handler handler = new Handler(); Timer t = new Timer(); t.schedule(new TimerTask() { public void run() { handler.post(new Runnable() { public void run() { AudioManager mgr = (AudioManager)context.getSystemService(context.AUDIO_SERVICE); mgr.setStreamMute(AudioManager.STREAM_SYSTEM, false); } }); } }, 1000);
– PankajAndroid
Jan 23 '13 at 10:28
@PankajJolapara you can post your own solution as an answer and accept the answer that solves your problem. This could help anyone who has the same problem. :)
– dumbfingers
Jan 23 '13 at 10:31
There are devices for which the proposed solution won't work, since they're set to always route the shutter sound to the loudspeaker and not allow it to be muted. Again, it depends largely on the market where the device was sold.
– Michael
Jan 23 '13 at 10:41
add a comment |
Thanks micheal and harism it's solve by this way for mute: AudioManager mgr =(AudioManager)context.getSystemService(context.AUDIO_SERVICE); mgr.setStreamMute(AudioManager.STREAM_SYSTEM, true); for unmute: final Handler handler = new Handler(); Timer t = new Timer(); t.schedule(new TimerTask() { public void run() { handler.post(new Runnable() { public void run() { AudioManager mgr = (AudioManager)context.getSystemService(context.AUDIO_SERVICE); mgr.setStreamMute(AudioManager.STREAM_SYSTEM, false); } }); } }, 1000);
– PankajAndroid
Jan 23 '13 at 10:28
@PankajJolapara you can post your own solution as an answer and accept the answer that solves your problem. This could help anyone who has the same problem. :)
– dumbfingers
Jan 23 '13 at 10:31
There are devices for which the proposed solution won't work, since they're set to always route the shutter sound to the loudspeaker and not allow it to be muted. Again, it depends largely on the market where the device was sold.
– Michael
Jan 23 '13 at 10:41
Thanks micheal and harism it's solve by this way for mute: AudioManager mgr =(AudioManager)context.getSystemService(context.AUDIO_SERVICE); mgr.setStreamMute(AudioManager.STREAM_SYSTEM, true); for unmute: final Handler handler = new Handler(); Timer t = new Timer(); t.schedule(new TimerTask() { public void run() { handler.post(new Runnable() { public void run() { AudioManager mgr = (AudioManager)context.getSystemService(context.AUDIO_SERVICE); mgr.setStreamMute(AudioManager.STREAM_SYSTEM, false); } }); } }, 1000);
– PankajAndroid
Jan 23 '13 at 10:28
Thanks micheal and harism it's solve by this way for mute: AudioManager mgr =(AudioManager)context.getSystemService(context.AUDIO_SERVICE); mgr.setStreamMute(AudioManager.STREAM_SYSTEM, true); for unmute: final Handler handler = new Handler(); Timer t = new Timer(); t.schedule(new TimerTask() { public void run() { handler.post(new Runnable() { public void run() { AudioManager mgr = (AudioManager)context.getSystemService(context.AUDIO_SERVICE); mgr.setStreamMute(AudioManager.STREAM_SYSTEM, false); } }); } }, 1000);
– PankajAndroid
Jan 23 '13 at 10:28
@PankajJolapara you can post your own solution as an answer and accept the answer that solves your problem. This could help anyone who has the same problem. :)
– dumbfingers
Jan 23 '13 at 10:31
@PankajJolapara you can post your own solution as an answer and accept the answer that solves your problem. This could help anyone who has the same problem. :)
– dumbfingers
Jan 23 '13 at 10:31
There are devices for which the proposed solution won't work, since they're set to always route the shutter sound to the loudspeaker and not allow it to be muted. Again, it depends largely on the market where the device was sold.
– Michael
Jan 23 '13 at 10:41
There are devices for which the proposed solution won't work, since they're set to always route the shutter sound to the loudspeaker and not allow it to be muted. Again, it depends largely on the market where the device was sold.
– Michael
Jan 23 '13 at 10:41
add a comment |
Well, all those solutions are good but i prefer setting the volume to 0 (and not only system since some devices users other streams then system and/or not all streams include system) before:
smth like this would work flawlessly:
Camera mCamera = null;
function takePicture() {
storeSoundSettings();
setMuteAll(true);
// init camera and such.
Camera.CameraInfo info = new Camera.CameraInfo();
Camera.getCameraInfo(IdOfCameraBackOrFront, info);
if (info.canDisableShutterSound) {
camera.enableShutterSound(false);
}
setMuteAll(false);
recoverSoundSettings();
}
and store, recover and setMuteAll something like this:
int streams = new int{
AudioManager.STREAM_ALARM,
AudioManager.STREAM_DTMF,
AudioManager.STREAM_MUSIC,
AudioManager.STREAM_NOTIFICATION,
AudioManager.STREAM_RING,
AudioManager.STREAM_SYSTEM,
AudioManager.STREAM_VOICE_CALL};
JSONObject json;
AudioManager manager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
public void storeSoundSettings() {
json = new JSONObject();
json.put("mode", manager.getMode());
json.put("ringermode", manager.getRingerMode());
for (int stream : streams) {
json.put("stream_" + stream, manager.getStreamVolume(stream));
}
}
public void recoverSoundSettings() {
json = new JSONObject(readString("last_audio_setting", null));
manager.setMode(json.getInt("mode"));
manager.setRingerMode(json.getInt("ringermode"));
for (int stream : streams) {
manager.setStreamVolume(stream, json.getInt("stream_" + stream), AudioManager.FLAG_ALLOW_RINGER_MODES);
}
public void setMuteAll(boolean mute) {
for (int stream : streams) {
manager.setStreamMute(stream, mute);
if (mute) {
manager.setStreamVolume(stream, 100, AudioManager.FLAG_ALLOW_RINGER_MODES);
} else {
manager.setStreamVolume(stream, 0, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
}
}
}
Do not forget to catch the exceptions. I removed them for better highlighting.
Are you miss with the setStreamVolume, it should be reversed
– Phuong
Aug 26 '16 at 14:02
add a comment |
Well, all those solutions are good but i prefer setting the volume to 0 (and not only system since some devices users other streams then system and/or not all streams include system) before:
smth like this would work flawlessly:
Camera mCamera = null;
function takePicture() {
storeSoundSettings();
setMuteAll(true);
// init camera and such.
Camera.CameraInfo info = new Camera.CameraInfo();
Camera.getCameraInfo(IdOfCameraBackOrFront, info);
if (info.canDisableShutterSound) {
camera.enableShutterSound(false);
}
setMuteAll(false);
recoverSoundSettings();
}
and store, recover and setMuteAll something like this:
int streams = new int{
AudioManager.STREAM_ALARM,
AudioManager.STREAM_DTMF,
AudioManager.STREAM_MUSIC,
AudioManager.STREAM_NOTIFICATION,
AudioManager.STREAM_RING,
AudioManager.STREAM_SYSTEM,
AudioManager.STREAM_VOICE_CALL};
JSONObject json;
AudioManager manager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
public void storeSoundSettings() {
json = new JSONObject();
json.put("mode", manager.getMode());
json.put("ringermode", manager.getRingerMode());
for (int stream : streams) {
json.put("stream_" + stream, manager.getStreamVolume(stream));
}
}
public void recoverSoundSettings() {
json = new JSONObject(readString("last_audio_setting", null));
manager.setMode(json.getInt("mode"));
manager.setRingerMode(json.getInt("ringermode"));
for (int stream : streams) {
manager.setStreamVolume(stream, json.getInt("stream_" + stream), AudioManager.FLAG_ALLOW_RINGER_MODES);
}
public void setMuteAll(boolean mute) {
for (int stream : streams) {
manager.setStreamMute(stream, mute);
if (mute) {
manager.setStreamVolume(stream, 100, AudioManager.FLAG_ALLOW_RINGER_MODES);
} else {
manager.setStreamVolume(stream, 0, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
}
}
}
Do not forget to catch the exceptions. I removed them for better highlighting.
Are you miss with the setStreamVolume, it should be reversed
– Phuong
Aug 26 '16 at 14:02
add a comment |
Well, all those solutions are good but i prefer setting the volume to 0 (and not only system since some devices users other streams then system and/or not all streams include system) before:
smth like this would work flawlessly:
Camera mCamera = null;
function takePicture() {
storeSoundSettings();
setMuteAll(true);
// init camera and such.
Camera.CameraInfo info = new Camera.CameraInfo();
Camera.getCameraInfo(IdOfCameraBackOrFront, info);
if (info.canDisableShutterSound) {
camera.enableShutterSound(false);
}
setMuteAll(false);
recoverSoundSettings();
}
and store, recover and setMuteAll something like this:
int streams = new int{
AudioManager.STREAM_ALARM,
AudioManager.STREAM_DTMF,
AudioManager.STREAM_MUSIC,
AudioManager.STREAM_NOTIFICATION,
AudioManager.STREAM_RING,
AudioManager.STREAM_SYSTEM,
AudioManager.STREAM_VOICE_CALL};
JSONObject json;
AudioManager manager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
public void storeSoundSettings() {
json = new JSONObject();
json.put("mode", manager.getMode());
json.put("ringermode", manager.getRingerMode());
for (int stream : streams) {
json.put("stream_" + stream, manager.getStreamVolume(stream));
}
}
public void recoverSoundSettings() {
json = new JSONObject(readString("last_audio_setting", null));
manager.setMode(json.getInt("mode"));
manager.setRingerMode(json.getInt("ringermode"));
for (int stream : streams) {
manager.setStreamVolume(stream, json.getInt("stream_" + stream), AudioManager.FLAG_ALLOW_RINGER_MODES);
}
public void setMuteAll(boolean mute) {
for (int stream : streams) {
manager.setStreamMute(stream, mute);
if (mute) {
manager.setStreamVolume(stream, 100, AudioManager.FLAG_ALLOW_RINGER_MODES);
} else {
manager.setStreamVolume(stream, 0, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
}
}
}
Do not forget to catch the exceptions. I removed them for better highlighting.
Well, all those solutions are good but i prefer setting the volume to 0 (and not only system since some devices users other streams then system and/or not all streams include system) before:
smth like this would work flawlessly:
Camera mCamera = null;
function takePicture() {
storeSoundSettings();
setMuteAll(true);
// init camera and such.
Camera.CameraInfo info = new Camera.CameraInfo();
Camera.getCameraInfo(IdOfCameraBackOrFront, info);
if (info.canDisableShutterSound) {
camera.enableShutterSound(false);
}
setMuteAll(false);
recoverSoundSettings();
}
and store, recover and setMuteAll something like this:
int streams = new int{
AudioManager.STREAM_ALARM,
AudioManager.STREAM_DTMF,
AudioManager.STREAM_MUSIC,
AudioManager.STREAM_NOTIFICATION,
AudioManager.STREAM_RING,
AudioManager.STREAM_SYSTEM,
AudioManager.STREAM_VOICE_CALL};
JSONObject json;
AudioManager manager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
public void storeSoundSettings() {
json = new JSONObject();
json.put("mode", manager.getMode());
json.put("ringermode", manager.getRingerMode());
for (int stream : streams) {
json.put("stream_" + stream, manager.getStreamVolume(stream));
}
}
public void recoverSoundSettings() {
json = new JSONObject(readString("last_audio_setting", null));
manager.setMode(json.getInt("mode"));
manager.setRingerMode(json.getInt("ringermode"));
for (int stream : streams) {
manager.setStreamVolume(stream, json.getInt("stream_" + stream), AudioManager.FLAG_ALLOW_RINGER_MODES);
}
public void setMuteAll(boolean mute) {
for (int stream : streams) {
manager.setStreamMute(stream, mute);
if (mute) {
manager.setStreamVolume(stream, 100, AudioManager.FLAG_ALLOW_RINGER_MODES);
} else {
manager.setStreamVolume(stream, 0, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
}
}
}
Do not forget to catch the exceptions. I removed them for better highlighting.
edited Mar 24 '16 at 20:24
akelec
1,95512528
1,95512528
answered Mar 25 '14 at 14:18
Emanuel S
5,77222042
5,77222042
Are you miss with the setStreamVolume, it should be reversed
– Phuong
Aug 26 '16 at 14:02
add a comment |
Are you miss with the setStreamVolume, it should be reversed
– Phuong
Aug 26 '16 at 14:02
Are you miss with the setStreamVolume, it should be reversed
– Phuong
Aug 26 '16 at 14:02
Are you miss with the setStreamVolume, it should be reversed
– Phuong
Aug 26 '16 at 14:02
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f14476791%2fandroid-mute-camera-shutter-sound%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I think this is somewhat undoable. At least in The States it was enforced by legislation to have all camera devices make a shutter sound. This is the case in some other countries too AFAIK.
– harism
Jan 23 '13 at 10:02
harism in some device it cause problem i had tested in nexus,s2,nexus table all device capture silently but htc desicer and some device cause problem.
– PankajAndroid
Jan 23 '13 at 10:15
is feeding the method with a silenced sound file a doable idea?
– dumbfingers
Jan 23 '13 at 10:29