这是我检测设备是否有手电筒的代码:
if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH) || (_camera.getParameters().getSupportedFlashModes() != null)) hasFlashlight = true;else hasFlashlight = false;
但即使设备只有没有手电筒的前置摄像头,它也是正确的.
解决方法 对于API> = 9:您可以使用 Camera.getCameraInfo这样的内容:int backCameraID = -1;for(int i=0;i<Camera.getNumberOfCameras();i++){ CameraInfo cameraInfo = new CameraInfo(); Camera.getCameraInfo(i,cameraInfo); if(cameraInfo.facing==CameraInfo.CAMERA_FACING_BACK) { backCameraID = i; break; }}Log.d(TAG,"back camera exists ? "+(backCameraID>-1));Log.d(TAG,"back camera ID :"+backCameraID);
对于API> = 21,建议您使用Camera2 API:
String backCameraID = null;CameraManager manager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);for(String cameraID:manager.getCameraIDList()){ Cameracharacteristics cameracharacteristics = manager.getCameracharacteristics(cameraID); Integer facing = cameracharacteristics.get(Cameracharacteristics.LENS_FACING); if(facing==CameraMetadata.LENS_FACING_BACK) { backCameraID = cameraID; break; }}Log.d(TAG,"back camera exists ? "+(backCameraID!=null));Log.d(TAG,"back camera ID :"+backCameraID);总结
以上是内存溢出为你收集整理的Android / Java:检测设备是否有BACK摄像头全部内容,希望文章能够帮你解决Android / Java:检测设备是否有BACK摄像头所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)