I have a problem that I want to decrease the brightness of the screen on the button click but failed to do that. I don’t know why? I have written the code of few lines but it doesn’t work for me. Please suggest me the right solution regarding the same.
Code:
private void setBrightness() {
try {
int curBrightnessValue = android.provider.Settings.System.getInt(getContentResolver(), android.provider.Settings.System.SCREEN_BRIGHTNESS);
WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
layoutParams.screenBrightness = curBrightnessValue/100.0f;
getWindow().setAttributes(layoutParams);
} catch (SettingNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Your code seems to good, but I think for taking effect of brightness your activity has to wait for
500ms, Just use given below code,UPDATE:
The main code is just,
Also try this..
Try this and let me know what happen,