get Camera Instance by Camera ID - Android Camera

Android examples for Camera:Camera Attribute

Description

get Camera Instance by Camera ID

Demo Code


//package com.java2s;

import android.hardware.Camera;

import android.util.Log;

public class Main {
    private static final String TAG = "CameraHelper";

    public static Camera getCameraInstance(int cameraId) {
        Camera c = null;/*from  w ww .j  a  va 2s.  com*/
        try {
            c = Camera.open(cameraId); // attempt to get a Camera instance
        } catch (Exception e) {
            Log.e(TAG, "open camera failed: " + e.getMessage());
            // Camera is not available (in use or does not exist)
        }
        return c; // returns null if camera is unavailable
    }
}

Related Tutorials