I am developing flashlight app. I want to set time like 2mins, 3mins and unlimited for the flashlight to be on. How can I do that?
First of all I am checking whether flashlight is available or not. If it is, I want to set the brightness to maximum.
My code contains the following.
if (flashcheck) {
camera = Camera.open();
parameters = camera.getParameters();
parameters.setFlashMode(Parameters.FLASH_MODE_TORCH);
camera.setParameters(parameters);
} else {
WindowManager.LayoutParams localLayoutParams = getWindow()
.getAttributes();
localLayoutParams.screenBrightness = 1F;
getWindow().setAttributes(localLayoutParams);
}
You can use the Handler for this, Check the below example:-
Whatever Runnable object you will pass as handler’s document, it will execute after 2000 milliseconds (means 2 seconds).