You can look at these two SO posts for checking, what light level is around you:
Lightsensor Value and Brightness of surrounding
But you have to decide, at which light level you'll turn the flashlight on.
Question
My code must automatically turn on the flashlight LED when the light is insufficient.
I can turn the flashlight on in the torch mode:
camera = Camera.open();
final Parameters p = camera.getParameters();
// ...
p.setFlashMode(Parameters.FLASH_MODE_TORCH);
camera.setParameters(p);
But I must not turn it on when it is not needed.
How do I find out, programmatically, whether I need to turn the flashlight on?
In other words, how can my application know if there's enough light?
Solution
You can look at these two SO posts for checking, what light level is around you:
Lightsensor Value and Brightness of surrounding
But you have to decide, at which light level you'll turn the flashlight on.
OTHER TIPS
If you wish have it turn on automatically while taking a photo if the light is insufficient, then FLASH_MODE_AUTO should do the trick for you