0

When I open the Camera using

Camera cam = Camera.open();

or

Camera cam = Camera.open(number);

How can I get information that this is the front or back camera? Some devices may have both, and some just one.

Sarkis
  • 303
  • 2
  • 12
Kitesurfer
  • 3,438
  • 2
  • 29
  • 47
  • possible duplicate of [How to open "front camera" on android platform?](http://stackoverflow.com/questions/2779002/how-to-open-front-camera-on-android-platform) – kiranpradeep May 23 '15 at 10:52

2 Answers2

3

Update:

Camera.CameraInfo was deprecated in API level 21. For newer versions see CameraCharacteristics.LENS_FACING. For more info, please see this answer.


First of all you may want to look at the reference of Camera class.

Methods getNumberOfCameras (does this device have only one camera or both?) and getCameraInfo (https://developer.android.com/reference/android/hardware/Camera.CameraInfo.html) will provide you with the exact information that you need.

There is an example of using both these methods:

private int findFrontFacingCamera() {
    int cameraId = -1;
    // Search for the front facing camera
    int numberOfCameras = Camera.getNumberOfCameras();
    for (int i = 0; i < numberOfCameras; i++) {
      CameraInfo info = new CameraInfo();
      Camera.getCameraInfo(i, info);
      if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
        Log.d(DEBUG_TAG, "Camera found");
        cameraId = i;
        break;
      }
    }
    return cameraId;
}
Yury Fedorov
  • 14,508
  • 6
  • 50
  • 66
0

first of all you should check if your device is supporting camera or not, and if the camera is supported then you get the number the number of available camera on your device.
<pre>CameraInfo cameraInfo = new CameraInfo();<br/> for (int i = 0; i < numberOfCameras; i++) { Camera.getCameraInfo(i, cameraInfo); if (cameraInfo.facing == CameraInfo.CAMERA_FACING_FRONT) { } }

you can use something like this to know which camera is open.

hope this will help you..