private Camera openFrontFacingCameraGingerbread() {

int cameraCount = 0;

Camera cam = null;

Camera.CameraInfo cameraInfo = new Camera.CameraInfo();

cameraCount = Camera.getNumberOfCameras();

for (int camIdx = 0; camIdx < cameraCount; camIdx++) {

Camera.getCameraInfo(camIdx, cameraInfo);

if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {

try {

cam = Camera.open(camIdx);

} catch (RuntimeException e) {

Log.e(TAG, "Camera failed to open: " + e.getLocalizedMessage());

}

}

}

return cam;

}

在AndroidManifest.xml文件中添加以下权限:

注意:此功能在Gingerbread(2.3)和Up Android Version中可用.

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐