gpt4 book ai didi

java - 前置摄像头无法连接摄像头服务?

转载 作者:行者123 更新时间:2023-11-30 09:27:15 26 4
gpt4 key购买 nike

我正在使用 Camera Api,因为当我启动应用程序时,它会显示后置摄像头,它工作正常,但是当我单击前置摄像头按钮时,它会出现运行时异常无法连接摄像头服务

in  camera = Camera.open(cameraID);

in front camera button code :

if (cameraID == Camera.CameraInfo.CAMERA_FACING_BACK)
{
Toast.makeText(getApplicationContext(), "Front Camera", Toast.LENGTH_LONG).show();

cameraID = Camera.CameraInfo.CAMERA_FACING_FRONT;

}
else if (cameraID == Camera.CameraInfo.CAMERA_FACING_FRONT)

{
Toast.makeText(getApplicationContext(), "Back Camera", Toast.LENGTH_LONG).show();

cameraID = Camera.CameraInfo.CAMERA_FACING_BACK;

}

Intent intent = getIntent();

finish();

startActivity(intent);

最佳答案

您是否授予前置摄像头权限:

<uses-permission android:name="android.permission.CAMERA" />
<uses-feature
android:name="android.hardware.camera"
android:required="false" />
<uses-feature
android:name="android.hardware.camera.front"
android:required="false" />
<uses-feature android:name="android.hardware.camera.autofocus" />

检查这个link1 & link2一次。

关于java - 前置摄像头无法连接摄像头服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14643224/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com