java.lang.RuntimeException:无法连接到相机服务 [英] java.lang.RuntimeException: Fail to Connect to camera service
本文介绍了java.lang.RuntimeException:无法连接到相机服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试制作一个可以打开和关闭相机闪光灯的应用.我的 atm 代码如下所示:
I tried to make an app than can switch my camera flash on and off. The code I have atm looks like this:
Camera flash;
Camera.Parameters params;
flash = Camera.open();
params = flash.getParameters();
params.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
flash.setParameters(params);
在清单 xml 中:
<permission android:name="android.permission.FLASHLIGHT"
android:permissionGroup="android.permission-group.HARDWARE_CONTROLS"
android:protectionLevel="normal" />
<permission android:name="android.permission.CAMERA"> </permission>
每次我运行代码时,应用程序都会在flash = Camera.open();"处崩溃出现此错误:
Everytime I run the code, the app crashes at "flash = Camera.open();" with this error:
java.lang.RuntimeException: 连接相机服务失败
java.lang.RuntimeException: Fail to Connect to camera service
我做错了什么?
推荐答案
要访问设备摄像头,你必须像这样在你的Android Manifest中声明CAMERA权限,
To access the device camera, you must declare the CAMERA permission in your Android Manifest like this,
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
这篇关于java.lang.RuntimeException:无法连接到相机服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文