我正在开发android marshmallow。在我的应用程序中,我正在尝试以编程方式打开Android移动前置摄像头以捕获用户个人资料pic&要显示它以供预览我已经尝试了很多可用的例子在互联网上没有给出完美的应用程序,每个例子都显示在按钮点击时加载后置摄像头。
答案 0 :(得分:0)
您可以通过
访问前置摄像头Camera.CameraInfo.CAMERA_FACING_FRONT
以下是您可以用来访问它的示例方法
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;
}