Example usage for android.hardware Camera getNumberOfCameras

List of usage examples for android.hardware Camera getNumberOfCameras

Introduction

In this page you can find the example usage for android.hardware Camera getNumberOfCameras.

Prototype

public native static int getNumberOfCameras();

Source Link

Document

Returns the number of physical cameras available on this device.

Usage

From source file:Main.java

/**
 * @param position Physical position of the camera i.e Camera.CameraInfo.CAMERA_FACING_FRONT
 *                 or Camera.CameraInfo.CAMERA_FACING_BACK.
 * @return the default camera id/*from  w w  w. ja  v  a2  s . c  o m*/
 */
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
private static int getDefaultCameraId(int position) {
    // Find the total number of cameras available
    int mNumberOfCameras = Camera.getNumberOfCameras();

    // Find the ID of the back-facing ("default") camera
    Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
    for (int i = 0; i < mNumberOfCameras; ++i) {
        Camera.getCameraInfo(i, cameraInfo);
        if (cameraInfo.facing == position)
            return i;
    }

    return -1;
}

From source file:Main.java

/**
 * @param position Physical position of the camera i.e Camera.CameraInfo.CAMERA_FACING_FRONT
 *                 or Camera.CameraInfo.CAMERA_FACING_BACK.
 * @return the default camera id/*from   w  w  w.ja v a  2 s .  c  om*/
 */
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
private static int getDefaultCameraId(int position) {
    // Find the total number of cameras available
    int mNumberOfCameras = Camera.getNumberOfCameras();

    // Find the ID of the back-facing ("default") camera
    Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
    for (int i = 0; i < mNumberOfCameras; i++) {
        Camera.getCameraInfo(i, cameraInfo);
        if (cameraInfo.facing == position) {
            return i;

        }
    }
    return -1;
}

From source file:Main.java

/**
 * @param position Physical position of the camera i.e Camera.CameraInfo.CAMERA_FACING_FRONT
 *                 or Camera.CameraInfo.CAMERA_FACING_BACK.
 * @return the default camera on the device. Returns null if camera is not available.
 */// ww  w .j av a  2 s .com
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
private static int getDefaultCamera(int position) {
    // Find the total number of cameras available
    int mNumberOfCameras = Camera.getNumberOfCameras();

    // Find the ID of the back-facing ("default") camera
    Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
    for (int i = 0; i < mNumberOfCameras; i++) {
        Camera.getCameraInfo(i, cameraInfo);
        if (cameraInfo.facing == position) {
            return i;

        }
    }

    return 0;
}

From source file:Main.java

/**
 * @param position Physical position of the camera i.e Camera.CameraInfo.CAMERA_FACING_FRONT
 *                 or Camera.CameraInfo.CAMERA_FACING_BACK.
 * @return the default camera on the device. Returns null if camera is not available.
 *///from  w  w w  . j  a v  a  2 s .  c o  m
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
private static Camera getDefaultCamera(int position) {
    // Find the total number of cameras available
    int mNumberOfCameras = Camera.getNumberOfCameras();

    // Find the ID of the back-facing ("default") camera
    Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
    for (int i = 0; i < mNumberOfCameras; ++i) {
        Camera.getCameraInfo(i, cameraInfo);
        if (cameraInfo.facing == position)
            return Camera.open(i);
    }

    return null;
}

From source file:Main.java

/**
 * @param position Physical position of the camera i.e Camera.CameraInfo.CAMERA_FACING_FRONT
 *                 or Camera.CameraInfo.CAMERA_FACING_BACK.
 * @return the default camera on the device. Returns null if camera is not available.
 *//*from  ww  w.j av  a 2 s.  c  o  m*/
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
public static Camera getDefaultCamera(int position) {
    // Find the total number of cameras available
    int mNumberOfCameras = Camera.getNumberOfCameras();

    // Find the ID of the back-facing ("default") camera
    Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
    for (int i = 0; i < mNumberOfCameras; i++) {
        Camera.getCameraInfo(i, cameraInfo);
        if (cameraInfo.facing == position) {
            try {
                return Camera.open(i);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    return null;
}

From source file:Main.java

/**
 *
 * @param position Physical position of the camera i.e Camera.CameraInfo.CAMERA_FACING_FRONT
 *                 or Camera.CameraInfo.CAMERA_FACING_BACK.
 * @return the default camera on the device. Returns null if camera is not available.
 *//* w  w w  . ja  va2 s. c om*/
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
private static Camera getDefaultCamera(int position) {
    // Find the total number of cameras available
    int mNumberOfCameras = Camera.getNumberOfCameras();

    // Find the ID of the back-facing ("default") camera
    Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
    for (int i = 0; i < mNumberOfCameras; i++) {
        Camera.getCameraInfo(i, cameraInfo);
        if (cameraInfo.facing == position) {
            return Camera.open(i);

        }
    }

    return null;
}

From source file:Main.java

/**
 *
 * @param position Physical position of the camera i.e Camera.CameraInfo.CAMERA_FACING_FRONT
 *                 or Camera.CameraInfo.CAMERA_FACING_BACK.
 * @return the default camera on the device. Returns null if camera is not available.
 *//*from w  ww . jav  a 2  s.  com*/
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
private static Camera getDefaultCamera(int position) {
    // Find the total number of cameras available
    int mNumberOfCameras = Camera.getNumberOfCameras();

    Log.d(TAG, "getDefaultCamera number:" + mNumberOfCameras + " position:" + position);

    // Find the ID of the back-facing ("default") camera
    Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
    for (int i = 0; i < mNumberOfCameras; i++) {
        Camera.getCameraInfo(i, cameraInfo);
        if (cameraInfo.facing == position) {
            return Camera.open(i);

        }
    }

    return null;
}

From source file:Main.java

public static int getDefaultCameraId(int position) {
    int mNumberOfCameras = Camera.getNumberOfCameras();

    // Find the ID of the back-facing ("default") camera
    Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
    for (int i = 0; i < mNumberOfCameras; i++) {
        Camera.getCameraInfo(i, cameraInfo);
        if (cameraInfo.facing == position) {
            return i;

        }/*from  w ww.j  a  v  a 2  s .  co m*/
    }
    return -1;
}

From source file:org.webrtc.videoengine.VideoCaptureDeviceInfoAndroid.java

private static String getDeviceInfo() {
    try {//from   w w w. j  av  a  2s  .c o m
        JSONArray devices = new JSONArray();
        for (int i = 0; i < Camera.getNumberOfCameras(); ++i) {
            CameraInfo info = new CameraInfo();
            Camera.getCameraInfo(i, info);
            String uniqueName = deviceUniqueName(i, info);
            JSONObject cameraDict = new JSONObject();
            devices.put(cameraDict);
            List<Size> supportedSizes;
            List<int[]> supportedFpsRanges;
            Camera camera = null;
            try {
                camera = Camera.open(i);
                Parameters parameters = camera.getParameters();
                supportedSizes = parameters.getSupportedPreviewSizes();
                supportedFpsRanges = parameters.getSupportedPreviewFpsRange();
                Log.d(TAG, uniqueName);
            } catch (RuntimeException e) {
                Log.e(TAG, "Failed to open " + uniqueName + ", skipping", e);
                continue;
            } finally {
                if (camera != null) {
                    camera.release();
                }
            }

            JSONArray sizes = new JSONArray();
            for (Size supportedSize : supportedSizes) {
                JSONObject size = new JSONObject();
                size.put("width", supportedSize.width);
                size.put("height", supportedSize.height);
                sizes.put(size);
            }

            JSONArray mfpsRanges = new JSONArray();
            for (int[] range : supportedFpsRanges) {
                JSONObject mfpsRange = new JSONObject();
                // Android SDK deals in integral "milliframes per second"
                // (i.e. fps*1000, instead of floating-point frames-per-second) so we
                // preserve that through the Java->C++->Java round-trip.
                mfpsRange.put("min_mfps", range[Parameters.PREVIEW_FPS_MIN_INDEX]);
                mfpsRange.put("max_mfps", range[Parameters.PREVIEW_FPS_MAX_INDEX]);
                mfpsRanges.put(mfpsRange);
            }

            cameraDict.put("name", uniqueName);
            cameraDict.put("front_facing", isFrontFacing(info)).put("orientation", info.orientation)
                    .put("sizes", sizes).put("mfpsRanges", mfpsRanges);
        }
        String ret = devices.toString(2);
        Log.d(TAG, ret);
        return ret;
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }
}

From source file:ac.blitz.acme.video.VideoCaptureDeviceInfoAndroid.java

private static String getDeviceInfo() {
    try {//from  ww w .j av  a  2s.  c  o m
        JSONArray devices = new JSONArray();
        for (int i = 0; i < Camera.getNumberOfCameras(); ++i) {
            CameraInfo info = new CameraInfo();
            Camera.getCameraInfo(i, info);
            String uniqueName = deviceUniqueName(i, info);
            JSONObject cameraDict = new JSONObject();
            devices.put(cameraDict);
            List<Size> supportedSizes;
            List<int[]> supportedFpsRanges;
            try {
                Camera camera = Camera.open(i);
                Parameters parameters = camera.getParameters();
                supportedSizes = parameters.getSupportedPreviewSizes();
                supportedFpsRanges = parameters.getSupportedPreviewFpsRange();
                camera.release();
                Log.d(TAG, uniqueName);
            } catch (RuntimeException e) {
                Log.e(TAG, "Failed to open " + uniqueName + ", skipping");
                continue;
            }
            JSONArray sizes = new JSONArray();
            for (Size supportedSize : supportedSizes) {
                JSONObject size = new JSONObject();
                size.put("width", supportedSize.width);
                size.put("height", supportedSize.height);
                sizes.put(size);
            }
            // Android SDK deals in integral "milliframes per second"
            // (i.e. fps*1000, instead of floating-point frames-per-second) so we
            // preserve that through the Java->C++->Java round-trip.
            int[] mfps = supportedFpsRanges.get(supportedFpsRanges.size() - 1);
            cameraDict.put("name", uniqueName);
            cameraDict.put("front_facing", isFrontFacing(info)).put("orientation", info.orientation)
                    .put("sizes", sizes).put("min_mfps", mfps[Parameters.PREVIEW_FPS_MIN_INDEX])
                    .put("max_mfps", mfps[Parameters.PREVIEW_FPS_MAX_INDEX]);
        }
        String ret = devices.toString(2);
        return ret;
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }
}