Reputation: 240
How to turn on camera flash light programmatically in Android?
my question us a variation of the above one i want to specifically set the duration for turning on the flash the value of which is found on runtime
is there any way to do this? thanks!
Upvotes: 0
Views: 2152
Reputation: 481
Here is a link to a tutorial for building a flashlight android application: android flashlight tutorial
I think the following lines may prove helpful to you:
"Turning on flashlight can be done by setting camera flash mode to FLASH_MODE_TORCH. The following two functions getCamera() and turnOnFlash() will do that for us. Add these functions to your [activity]"
To turn off the flash by setting the camera flash mode to "FLASH_MODE_OFF"
The code for the 'getCamera()' and 'turnOnFlash()' functions can be found by following the link above.. So, I urge you to follow the link and check out the code samples they've posted in steps 8 and 9, they should help you to get the light turning on and off programmatically.
Next, in order to get the code to run on a specific time interval you can implement a runnable to turn the flashlight off a specific amount of time after it was turned on.
Here is an example of how to run the turnOffFlash() function (or whatever you have called it) with a delay.
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
turnOffFlash();
}
}, 10000);
Replace 10000 with your delay in millis.
Upvotes: 1