Android Fail to connect to camera service

在一个Activity中已经初始化了主摄像头Camera0,并且开始录像。
然后打开一个悬浮窗,初始化Camera1,打开失败,提示“Fail to connect to camera service”。如果Activity中的Camera0只预览不录像,则悬浮窗中的Camera1可以正常打开并且预览。

    /**
     * 打开摄像头
     * 
     * @return
     */
    private boolean openViceCamera() {
        MyLog.v("[BackCarService]camera openning");
        if (camera != null) {
            closeCamera();
        }
        try {
            Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
            int cameraCount = Camera.getNumberOfCameras();

            MyLog.v("[BackCarService]cameraCount:" + cameraCount + ",Open 1");
            camera = Camera.open(1);
            camera.lock();
            camera.setPreviewDisplay(surfaceHolder);
            camera.startPreview();
            camera.unlock();
            return true;
        } catch (Exception ex) {
            closeCamera();
            MyLog.e("[BackCarService]openCamera:Catch Exception:" + ex);
            return false;
        }
    }

规避方案:
1.在Camera0开始录像之前初始化Camera1;
2.修改CamManager.cpp中getPermission()的返回值。

你可能感兴趣的:(Android)