Using setFlashMode - Android 2.2
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开发者_如何学Go I go in the documentation to find out what imports are needed for what statements, constants .....
Regards,
Oliver
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.
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
精彩评论