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.
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.
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;
}
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..