public static int getCameraId(int requestedId) {
        int numCameras = Camera.getNumberOfCameras();
        if (numCameras == 0) {
            Log.w(TAG, "No cameras!");
            return -1;
        }

        int cameraId = requestedId;

        boolean explicitRequest = cameraId >= 0;

        if (!explicitRequest) {
            // Select a camera if no explicit camera requested
            int index = 0;
            while (index < numCameras) {
                Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
                Camera.getCameraInfo(index, cameraInfo);
                if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
                    break;
                }
                index++;
            }

            cameraId = index;
        }

        if (cameraId < numCameras) {
            return cameraId;
        } else {
            if (explicitRequest) {
                return -1;
            } else {
                return 0;
            }
        }
    }
For {@link #open(int)}, means no preference for which camera to open.
zxing-android-embedded/src/com/google/zxing/client/android/camera/open/OpenCameraInterface.java