检测设备是否存在前置摄像头

照相机,我自己写的代码:

mMediaRecorderVideo=new MediaRecorder();
mCamera=Camera.open();      
mCamera.setDisplayOrientation(90);
mCamera.unlock();
mMediaRecorderVideo.setCamera(mCamera);
mMediaRecorderVideo.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
mMediaRecorderVideo.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
mMediaRecorderVideo.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));

使用设备的默认相机,但是如果有前置相机需要设置,应该怎么检测?谢谢

int numCameras= Camera.getNumberOfCameras();
for(int i=0;i<numCameras;i++){
    Camera.CameraInfo info = new CameraInfo();
    Camera.getCameraInfo(i, info);
    if(CAMERA_FACING_FRONT == info.facing){
        return true;
    }
}
return false;

如果你还要得到前置相机的数量,那么在return中返回i,0返回not found

int cameraId = android.hardware.Camera.getNumberOfCameras();

cameraId大于1就是有两个以上的摄像头,打开用open(int id),id为0到cameraId-1