1

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?

iknow
  • 8,358
  • 12
  • 41
  • 68
surendra
  • 2,217
  • 7
  • 34
  • 42
  • Hi Surendra, i also having same requirement as like you, did you get any solution for this issue? if so please send me the solution, it is very greatful if you send the working code snippet. my id is sathya.sri69@gmail.com – sathish Apr 12 '12 at 06:29

3 Answers3

0

Have you used surface view to turn on the flash light, which device are you using as some of the devices do require surface view to make flash run in it.

Here's a link!

Community
  • 1
  • 1
Syed Raza Mehdi
  • 4,067
  • 1
  • 31
  • 47
0

You can reuse your existing camera object and just setParameters on that. Note that not all devices support flash mode torch. Also some, like the fascinate/epic (who actually use flash mode on) cannot change the state without disconnecting and reconnecting to the camera.

Kevin TeslaCoil
  • 10,037
  • 1
  • 39
  • 33
0

You are accessing camera settings and camera. Check if you have a android.permission.CAMERA in AndroidMainfest.xml uses-permissions.

evilone
  • 22,410
  • 7
  • 80
  • 107