I want to turn off the screen when the user clicks a button. I am trying to do it with PowerManager class but I don't obtain good results. What is the best way to turn off the screen in android?.
I am using the code below:
PowerManager pm = (PowerManager)this.getSystemService( Context.POWER_SERVICE); PowerManager.WakeLock wl = pm.newWakeLock( PowerManager.PARTIAL_WAKE_LOCK, ""); wl.acquire();
But only work this code:
WindowManager.LayoutParams params = getWindow().getAttributes(); params.flags = WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON; params.screenBrightness = 0; getWindow().setAttributes(params);
But, this code only set brightness to 0 but no turns off the screen.
Thanks a lot.