Skip to content

Commit 69fe527

Browse files
author
Eino-Ville Talvala
committed
Camera: Add enableShutterSound method.
Some camera apps may wish to replace the system camera shutter sound with their own, especially if they are taking rapid bursts of images. Add method to allow this when possible. Hidden for now. Change-Id: I6520f5441d28675626fafab48c6609c589fc6f7e
1 parent 753e128 commit 69fe527

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

core/java/android/hardware/Camera.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,6 +1145,31 @@ public final void takePicture(ShutterCallback shutter, PictureCallback raw,
11451145
*/
11461146
public native final void setDisplayOrientation(int degrees);
11471147

1148+
/**
1149+
* Enable or disable the default shutter sound when taking a picture.
1150+
*
1151+
* By default, the camera plays the system-defined camera shutter sound when
1152+
* {@link #takePicture} is called. Using this method, the shutter sound can
1153+
* be disabled. It is strongly recommended that an alternative shutter sound
1154+
* is played in the {@link ShutterCallback} when the system shutter sound is
1155+
* disabled.
1156+
*
1157+
* Note that devices may not always allow control of the camera shutter
1158+
* sound. If the shutter sound cannot be controlled, this method will return
1159+
* false.
1160+
*
1161+
* @param enabled whether the camera should play the system shutter sound
1162+
* when {@link #takePicture takePicture} is called.
1163+
* @return true if the shutter sound state was successfully changed. False
1164+
* if the shutter sound cannot be controlled; in this case, the
1165+
* application should not play its own shutter sound since the
1166+
* system shutter sound will play when a picture is taken.
1167+
* @see #takePicture
1168+
* @see ShutterCallback
1169+
* @hide
1170+
*/
1171+
public native final boolean enableShutterSound(boolean enabled);
1172+
11481173
/**
11491174
* Callback interface for zoom changes during a smooth zoom operation.
11501175
*

core/jni/android_hardware_Camera.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,25 @@ static void android_hardware_Camera_setDisplayOrientation(JNIEnv *env, jobject t
781781
}
782782
}
783783

784+
static jboolean android_hardware_Camera_enableShutterSound(JNIEnv *env, jobject thiz,
785+
jboolean enabled)
786+
{
787+
ALOGV("enableShutterSound");
788+
sp<Camera> camera = get_native_camera(env, thiz, NULL);
789+
if (camera == 0) return JNI_FALSE;
790+
791+
int32_t value = (enabled == JNI_TRUE) ? 1 : 0;
792+
status_t rc = camera->sendCommand(CAMERA_CMD_ENABLE_SHUTTER_SOUND, value, 0);
793+
if (rc == NO_ERROR) {
794+
return JNI_TRUE;
795+
} else if (rc == PERMISSION_DENIED) {
796+
return JNI_FALSE;
797+
} else {
798+
jniThrowRuntimeException(env, "enable shutter sound failed");
799+
return JNI_FALSE;
800+
}
801+
}
802+
784803
static void android_hardware_Camera_startFaceDetection(JNIEnv *env, jobject thiz,
785804
jint type)
786805
{
@@ -890,6 +909,9 @@ static JNINativeMethod camMethods[] = {
890909
{ "setDisplayOrientation",
891910
"(I)V",
892911
(void *)android_hardware_Camera_setDisplayOrientation },
912+
{ "enableShutterSound",
913+
"(Z)Z",
914+
(void *)android_hardware_Camera_enableShutterSound },
893915
{ "_startFaceDetection",
894916
"(I)V",
895917
(void *)android_hardware_Camera_startFaceDetection },

0 commit comments

Comments
 (0)