Anyone who knows why this code ain\'t lowering the backlight of my application?
Context context = this;
Settings.System.putInt(context.getContentResolve
If you want to change the brightness of your current application, use the code hackbod posted
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = ;
getWindow().setAttributes(lp);
But I cannot fully agree with hackbod's post. It is definitely possible to change the global brightness without using hacks. I just wrote a short demo application.
The trick is, that first the application's brightness has to be changed and then change the global brightness. Otherwise only the "brightness slider" in the settings menu changes its position but this does not affect the brightness. Only if the user taps on the slider, the brightness will be applied.
WindowManager.LayoutParams localLayoutParams = getWindow()
.getAttributes();
localLayoutParams.screenBrightness = 0.12F;
getWindow().setAttributes(localLayoutParams);
Settings.System.putInt(this.resolver, "screen_brightness", 30);
application brightness range from 0 - 1 global brightness range from 0 - 255 (0 = display off)
Also it is very important to wait some time to apply the settings if you want to exit afterwards.
Thread t = new Thread(new Runnable() {
public void run() {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
System.out.println(e);
}
System.out.println("finally exit");
finish();
}
});
t.start();