Android摄像头Bug记录
1. Fail to connect to camera service,无法连接Camera服务
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.reeman.bigman/com.reeman.hellorobot.MainActivity}: java.lang.RuntimeException: Fail to connect to camera service
…
Caused by: java.lang.RuntimeException: Fail to connect to camera service
···
报错信息中提示无法连接到摄像头,可能情况及解决方法如下:
- 代码中打开的是否是对应的摄像头,如前置、后置、usb。
- AndroidManifest.xml中是否配置了相机权限
<uses-permission android:name="android.permission.CAMERA" />
,另外,6.0以上的系统还需要动态过去权限。 - 设备中限制了该应用获取相机权限,需要在设备中找到权限管理中心手动赋予权限。
前面打开Camera后,在关闭时没有进行释放操作。释放操作的代码如下:
camera.stopPreview();
camera.release();
camera = null;