看了写一些资料后面自己总结了下,大概整理为如下:
//判断是否有前置摄像头
private int FindFrontCamera() {
int cameraCount = 0;
Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
cameraCount = Camera.getNumberOfCameras(); // get cameras number
for (int camIdx = 0; camIdx < cameraCount; camIdx++) {
Camera.getCameraInfo(camIdx, cameraInfo); // get camerainfo
if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
// 代表摄像头的方位,目前有定义值两个分别为CAMERA_FACING_FRONT前置和CAMERA_FACING_BACK后置
return camIdx;
}
}
return -1;
}
//判断是否有后置摄像头
private int FindBackCamera() {
int cameraCount = 0;
Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
cameraCount = Camera.getNumberOfCameras(); // get cameras number
for (int camIdx = 0; camIdx < cameraCount; camIdx++) {
Camera.getCameraInfo(camIdx, cameraInfo); // get camerainfo
if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
// 代表摄像头的方位,目前有定义值两个分别为CAMERA_FACING_FRONT前置和CAMERA_FACING_BACK后置
return camIdx;
}
}
return -1;
}
然后找到ZXing封装的工具类里面的CameraManager类中的:
在请求摄像头id(requestedCameraId)的时候让它去查找摄像头的前置id,然后传入.open(requestedCameraId)方法,即可实现调用前置摄像头扫描的功能(我这前置是1,后置是0)。
相当于做个笔记吧,希望对大家有所帮助。
来源:CSDN
作者:丿丶小小江
链接:https://blog.csdn.net/qq_34234070/article/details/103235204