Camera.javaAPI DocAndroid 1.5 API25398Wed May 06 22:41:54 BST 2009android.hardware


public class Camera extends Object
The Camera class is used to connect/disconnect with the camera service, set capture settings, start/stop preview, snap a picture, and retrieve frames for encoding for video.

There is no default constructor for this class. Use {@link #open()} to get a Camera object.

Fields Summary
private static final String
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private int
private EventHandler
private ShutterCallback
private PictureCallback
private PictureCallback
private PreviewCallback
private AutoFocusCallback
private ErrorCallback
private boolean
public static final int
Unspecified camerar error. @see #ErrorCallback
public static final int
Media server died. In this case, the application must release the Camera object and instantiate a new one. @see #ErrorCallback
Constructors Summary

        mShutterCallback = null;
        mRawImageCallback = null;
        mJpegCallback = null;
        mPreviewCallback = null;

        Looper looper;
        if ((looper = Looper.myLooper()) != null) {
            mEventHandler = new EventHandler(this, looper);
        } else if ((looper = Looper.getMainLooper()) != null) {
            mEventHandler = new EventHandler(this, looper);
        } else {
            mEventHandler = null;

        native_setup(new WeakReference<Camera>(this));
Methods Summary
public final voidautoFocus(android.hardware.Camera$AutoFocusCallback cb)
Starts auto-focus function and registers a callback function to run when camera is focused. Only valid after startPreview() has been called.

cb the callback to run

        mAutoFocusCallback = cb;
protected voidfinalize()

public android.hardware.Camera$ParametersgetParameters()
Returns the picture Parameters for this Camera service.

        Parameters p = new Parameters();
        String s = native_getParameters();
        Log.e(TAG, "_getParameters: " + s);
        return p;
public final native intlock()
Lock the camera to prevent other processes from accessing it. To save setup/teardown time, a client of Camera can pass an initialized Camera object to another process. This method is used to re-lock the Camera object prevent other processes from accessing it. By default, the Camera object is locked. Locking it again from the same process will have no effect. Attempting to lock it from another process if it has not been unlocked will fail. Returns 0 if lock was successful. FIXME: Unhide after approval


private final native voidnative_autoFocus()

private final native java.lang.Stringnative_getParameters()

private final native voidnative_release()

private final native voidnative_setParameters(java.lang.String params)

private final native voidnative_setup(java.lang.Object camera_this)

private final native voidnative_takePicture()

public static android.hardware.Cameraopen()
Returns a new Camera object.

        return new Camera(); 
private static voidpostEventFromNative(java.lang.Object camera_ref, int what, int arg1, int arg2, java.lang.Object obj)

        Camera c = (Camera)((WeakReference)camera_ref).get();
        if (c == null)

        if (c.mEventHandler != null) {
            Message m = c.mEventHandler.obtainMessage(what, arg1, arg2, obj);
public final native booleanpreviewEnabled()
Return current preview state. FIXME: Unhide before release


public final native voidreconnect()
Reconnect to the camera after passing it to MediaRecorder. To save setup/teardown time, a client of Camera can pass an initialized Camera object to a MediaRecorder to use for video recording. Once the MediaRecorder is done with the Camera, this method can be used to re-establish a connection with the camera hardware. NOTE: The Camera object must first be unlocked by the process that owns it before it can be connected to another proces.

IOException if the method fails. FIXME: Unhide after approval

public final voidrelease()
Disconnects and releases the Camera object resources.

It is recommended that you call this as soon as you're done with the Camera object.

public final voidsetErrorCallback(android.hardware.Camera$ErrorCallback cb)
Registers a callback to be invoked when an error occurs.

cb the callback to run


        mErrorCallback = cb;
private final native voidsetHasPreviewCallback(boolean installed, boolean oneshot)

public final voidsetOneShotPreviewCallback(android.hardware.Camera$PreviewCallback cb)
Installs a callback to retrieve a single preview frame, after which the callback is cleared.

cb A callback object that receives a copy of the preview frame.

        if (cb != null) {
            mPreviewCallback = cb;
            mOneShot = true;
            setHasPreviewCallback(true, true);
public voidsetParameters(android.hardware.Camera$Parameters params)
Sets the Parameters for pictures from this Camera service.

params the Parameters to use for this Camera service

        Log.e(TAG, "setParameters()");
public final voidsetPreviewCallback(android.hardware.Camera$PreviewCallback cb)
Can be called at any time to instruct the camera to use a callback for each preview frame in addition to displaying it.

cb A callback object that receives a copy of each preview frame. Pass null to stop receiving callbacks at any time.

        mPreviewCallback = cb;
        mOneShot = false;
        setHasPreviewCallback(cb != null, false);
public final voidsetPreviewDisplay(android.view.SurfaceHolder holder)
Sets the SurfaceHolder to be used for a picture preview. If the surface changed since the last call, the screen will blank. Nothing happens if the same surface is re-set.

holder the SurfaceHolder upon which to place the picture preview
IOException if the method fails.

private final native voidsetPreviewDisplay(android.view.Surface surface)

public final native voidstartPreview()
Start drawing preview frames to the surface.

public final native voidstopPreview()
Stop drawing preview frames to the surface.

public final voidtakePicture(android.hardware.Camera$ShutterCallback shutter, android.hardware.Camera$PictureCallback raw, android.hardware.Camera$PictureCallback jpeg)
Triggers an asynchronous image capture. The camera service will initiate a series of callbacks to the application as the image capture progresses. The shutter callback occurs after the image is captured. This can be used to trigger a sound to let the user know that image has been captured. The raw callback occurs when the raw image data is available. The jpeg callback occurs when the compressed image is available. If the application does not need a particular callback, a null can be passed instead of a callback method.

shutter callback after the image is captured, may be null
raw callback with raw image data, may be null
jpeg callback with jpeg image data, may be null

        mShutterCallback = shutter;
        mRawImageCallback = raw;
        mJpegCallback = jpeg;
public final native intunlock()
Unlock the camera to allow aother process to access it. To save setup/teardown time, a client of Camera can pass an initialized Camera object to another process. This method is used to unlock the Camera object before handing off the Camera object to the other process. Returns 0 if unlock was successful. FIXME: Unhide after approval