If you use API level 9 (Android 2.3) or higher, you can do the following to calculate the index of the (first) front camera:
int getFrontCameraId() { CameraInfo ci = new CameraInfo(); for (int i = 0 ; i < Camera.getNumberOfCameras(); i++) { Camera.getCameraInfo(i, ci); if (ci.facing == CameraInfo.CAMERA_FACING_FRONT) return i; } return -1;
you can use the index for the Camera.open method, for example:
int index = getFrontCameraId(); if (index == -1) error(); Camera c = Camera.open(index);
To get the appropriate camera.
source share