I need to turn the screen off/on based on the proximity sensor.
From various other messages, it seems you can turn the screen off using the following code:
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.buttonBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_OFF;
lp.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_OFF;
getWindow().setAttributes(lp);
I am running into two problems with this code:
- It does not completely turn off the screen. It just dims the screen.
- The input controls (buttons, etc.) stay enabled.
I also looked at wake lock example. However, I couldn't get it work. Here is the code:
void turnScreenOff() {
PowerManager manager = (PowerManager) getSystemService(Context.POWER_SERVICE);
this._wakeLock = manager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "my tag");
this._wakeLock.acquire();
}
What is it that I am missing? Regards.