I am doing a barcode scanning app in android. In that, I have to turn on the camera flash light dynamically and I am doing this by using the following code
mCamera = Camera.open();
Camera.Parameters params = mCamera.getParameters();
params.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
mCamera.setParameters(params);
mCamera.startPreview();
But it's showing an Exception like:
ERROR/AndroidRuntime(17291): java.lang.RuntimeException: Fail to connect to camera service
at line
mCamera = Camera.open();
I think the exception is because while I am scanning the barcode the camera is already in open mode and here I am trying to open the camera again.
Is there any way to turn on the Flash light without open the camera again ? and how?