1

Want to switch light on/off and not succeeding. Probably not getting the most from th documentation. In any event, this is what I have tried.

Amongst the imports I have

import android.hardware.Camera;

Within the body

Camera myCamera;
.......
myCamera = Camera.open();
.......
Camera.Parameters myCameraParameters = myCamera.getParameters();
myCameraParameters.setFlashMode(FLASH_MODE_TORCH);

The above line brings up an error 'FLASH_MODE_TORCH cannot be resolved to a variable' I am assuming that I am missing an import which defines FLASH_MODE_TORCH.

Anyine point me in the right direction?

IF I am missing an import, where should I go in the documentation to find out what imports are needed for what statements, constants .....

Regards,

Oliver

LenseOnLife
  • 179
  • 1
  • 7
  • 16

2 Answers2

2

I believe it should be Camera.Parameters.FLASH_MODE_TORCH. I was having some difficulty getting visibility to this parameter, but you should take a look at this questions They seem to have it figured out with an example.

Community
  • 1
  • 1
Nick Campion
  • 10,479
  • 3
  • 44
  • 58
  • Hi, thanks for the info. What I did (a pure guess on my part!) was myCameraParameters.setFlashMode("on") or "off" will turn off the light and myCameraParameters.setFlashMode("torch") turns it on. BUT, I would like to know how/where FLASH_MODE_TORCH is set because it is coming up as unknown in my compiler/Eclipse. There must be some way in the documentation of knowing what to include when you find a predefined constant (like FLASH_MODE_TORCH). Any ideas? – LenseOnLife Jan 31 '11 at 21:43
  • I actually had the exact same issue. I can't seem to get the value to show up in my IDE. I think its a visibility issue, but I see in the doc that the constant value for FLASH_MODE_TORCH = "torch". I'm not sure how to fix it. – Nick Campion Jan 31 '11 at 22:09
2

This code might help comeone else

            Camera.Parameters myCameraParameters = myCamera.getParameters();
            String stringFlashMode;
            stringFlashMode = myCameraParameters.getFlashMode();
            if (stringFlashMode.equals("torch"))
                    myCameraParameters.setFlashMode("on"); // Light is set off, flash is set to normal 'on' mode
            else
                    myCameraParameters.setFlashMode("torch"); // This turns the light on
            myCamera.setParameters(myCameraParameters);

Regards,

Oliver

LenseOnLife
  • 179
  • 1
  • 7
  • 16