2

我正在使用 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);
4

1 回答 1

2

您是否允许前置摄像头:

<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" />

检查此链接 1链接2一次。

于 2013-02-01T09:52:51.607 回答