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

public static int getCameraNumbers() {
    return Camera.getNumberOfCameras();
}

From source file:Main.java

private static Camera getFrontCamera() {
    for (int i = 0; i < Camera.getNumberOfCameras(); i++) {
        Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
        Camera.getCameraInfo(i, cameraInfo);

        if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
            return Camera.open(i);
        }//from  w ww  .  j av  a  2 s .  c  om
    }

    return null;
}

From source file:Main.java

public static boolean isCurrentCameraFrontFacing() {
    int mNumberOfCameras = Camera.getNumberOfCameras();
    boolean returnValue = false;
    if (mNumberOfCameras > 1)
        returnValue = true;/*w w w .j a v a 2 s .c  om*/
    return returnValue;
}

From source file:Main.java

public static int getFrontCameraId() throws Exception {
    int numberOfCameras = Camera.getNumberOfCameras();
    Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
    for (int i = 0; i < numberOfCameras; i++) {
        Camera.getCameraInfo(i, cameraInfo);
        if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
            return i;
        }//from  w  ww  . j a v a2  s  .  c  o  m
    }

    return 0;
}

From source file:Main.java

public static boolean hasFewCamera() {
    return Camera.getNumberOfCameras() > 1 && hasFrontCamera();
}

From source file:Main.java

public static int getCameraId(int cameraFacing) {
    int count = Camera.getNumberOfCameras();

    if (count > 0) {
        Camera.CameraInfo info = new Camera.CameraInfo();
        for (int i = 0; i < count; i++) {
            Camera.getCameraInfo(i, info);
            if (info.facing == cameraFacing) {
                return i;
            }//from w ww  .  j av a2  s. co m
        }
    }
    return -1;
}

From source file:Main.java

public static int getFrontCameraId() {
    Camera.CameraInfo ci = new Camera.CameraInfo();
    for (int i = 0; i < Camera.getNumberOfCameras(); i++) {
        Camera.getCameraInfo(i, ci);//from  ww  w. j a va 2 s  .c o m
        if (ci.facing == Camera.CameraInfo.CAMERA_FACING_FRONT)
            return i;
    }
    return -1; // No front-facing camera found
}

From source file:Main.java

public static int getCameraByDirection(int direction) {
    int numCameras = Camera.getNumberOfCameras();
    CameraInfo info = new CameraInfo();
    for (int camid = 0; camid < numCameras; camid++) {
        Camera.getCameraInfo(camid, info);
        if (info.facing == direction) {
            return camid;
        }/*www  .ja va  2 s.  co m*/
    }
    return -1;
}

From source file:Main.java

private static void obtainCameraRatios() {
    for (int i = 0; i < Camera.getNumberOfCameras(); i++) {
        Camera camera = Camera.open(i);//from w  w w  .j  av a  2  s.c  o  m
        Camera.CameraInfo info = new Camera.CameraInfo();
        Camera.getCameraInfo(i, info);
        if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
            frontCameraRatio = camera.getParameters().getPreferredPreviewSizeForVideo();
        } else {
            backCameraRatio = camera.getParameters().getPreferredPreviewSizeForVideo();
        }
        camera.release();
    }
}

From source file:Main.java

private static int findCamera(int type) {
    int cameraId = -1;
    // Search for the front facing camera
    int numberOfCameras = Camera.getNumberOfCameras();
    for (int i = 0; i < numberOfCameras; i++) {
        Camera.CameraInfo info = new Camera.CameraInfo();
        Camera.getCameraInfo(i, info);// ww w  .j  a v a  2s.com
        if (info.facing == type) {
            cameraId = i;
            break;
        }
    }
    return cameraId;
}