I have some problem with WindowManager.LayoutParams. I need to poweroff and poweron the screen using the proximity sensors. The proximity sensor is OK, but layoutParams doesn't work
public void setBright(float value) {
Window mywindow = getWindow();
WindowManager.LayoutParams lp = mywindow.getAttributes();
lp.screenBrightness = value;
lp.buttonBrightness = value;
if (value != WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_OFF) {
lp.flags |= WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
}
mywindow.setAttributes(lp);
}
The screen poweroff correctly. But if I use setBright(WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE) the screen remains black. I also tried using wakeLock
private void powerOnScreen() {
setBright(WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE);
onResume();
if (!wakeLock.isHeld())
wakeLock.acquire();
}
where wakeLock is:
PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
wakeLock = powerManager.newWakeLock(
PowerManager.SCREEN_DIM_WAKE_LOCK
| PowerManager.ON_AFTER_RELEASE,
"MY_TAG");
but it still doesn't work. Any idea? Target platform is Android 2.2