开发者

Camera function in background service

I am developing an application where I need to access device camera from android background service.I am getting this error "Fail to connect to camera service".Can anybody help in this regards

Here is my ImageGrab function

    void grapImage() {
    mCamera = Camera.open();
    parameters = mCamera.getParameters();
    mCamera.setParameters(parameters);
    //mCamera.startPreview();
    mCamera.stopPreview();
    Camera.PictureCallback mCall = new Camera.PictureCallback() {
        @Override
        public void onPictureTaken(byte[] data, Camera camera) {
            bmp = BitmapFactory.decodeByteArray开发者_运维知识库(data, 0, data.length);
        }
    };
    mCamera.takePicture(null, null, mCall);
    mCamera.unlock();
    mCamera.release();
}

Thanks in advance.

Regards

Altaf


You must pass a fully initialized SurfaceHolder. I don't believe this can be done from a Service. Make sure you have the right permissions enabled in the Manifest and follow the procedures laid out in the documentation. That tells you exactly how to work with the camera. It states that you must start a preview before you can take a picture. Again, not sure if this is possible from a service but you might be able to find a "hack" or work around using the link provided.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜