I can't turn off the screen using this code. I used PowerManager
and wl.release()
method, but it doesn't work. Can somebody show me an example?
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "DoNotDimScreen");
This is part of my function:
stateString = "nextone";
if(stateString=="nextone"){
wl.release();
}
I also added permission in the manifest but no result.
I found the answer over here on stack overflow: Turn off screen on Android
Copied from there:
WindowManager.LayoutParams params = getWindow().getAttributes();
params.flags |= LayoutParams.FLAG_KEEP_SCREEN_ON;
params.screenBrightness = 0;
getWindow().setAttributes(params);
I tried this out and it seems to work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With