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.
精彩评论