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);
And in the manifest xml:
android:permissionGroup="android.permission-group.HARDWARE_CONTROLS"
android:protectionLevel="normal" />
Everytime I run the code, the app crashes at "flash = Camera.open();" with this error:
java.lang.RuntimeException: Fail to Connect to camera service
What am I doing wrong?
解决方案
To access the device camera, you must declare the CAMERA permission in your Android Manifest like this,
开发者分享了尝试创建一个能切换手机摄像头闪光灯的应用时遇到的问题,代码中`Camera.open()`失败,报错'Fail to connect to camera service'。文章探讨了AndroidManifest.xml中的权限配置,以及如何正确声明CAMERA权限以避免应用崩溃。

810

被折叠的 条评论
为什么被折叠?



