0

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:

  1. It does not completely turn off the screen. It just dims the screen.
  2. 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.

Peter
  • 11,260
  • 14
  • 78
  • 155
  • Here is a link to a [similar question](http://stackoverflow.com/questions/9561320/android-how-to-turn-screen-on-and-off-programmatically) – tupini07 Oct 23 '14 at 02:01
  • Thank you. Most of my implementation came from that post. However, it still doesn't work as I wanted. – Peter Oct 23 '14 at 04:11

0 Answers0