francas
francas

Reputation: 331

Set the screen brightness to the minimum

I have problems trying to set the screen brightness to the minimum. My code is the following:

        WindowManager.LayoutParams params = w.getAttributes();
        params.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_OFF;
        w.setAttributes(params);

The problem is that the screen turns off completely in some devices and it is almost impossible to turn the screen on again even pressing the power button (fortunately the screen turns on again after a while). I have no idea about this behavior.

Help please. Thanks in advance.

Fran.

Upvotes: 4

Views: 1538

Answers (2)

Merkost
Merkost

Reputation: 2376

Just set it on zero

private fun Window.setScreenBrightness(brightness: Float) {
    val lp = attributes
    lp.screenBrightness = brightness
    attributes = lp
}

window.setScreenBrightness(0f)

Upvotes: 0

Punith K
Punith K

Reputation: 666

Try this,

WindowManager.LayoutParams layout = getWindow().getAttributes();
layout.screenBrightness = 1F;
getWindow().setAttributes(layout);

And also check the Official Documentation Screen Brightness

try change the values with 0.1 precision in layout.screenBrightness = 0.1F or 0.2F and so on.

I hope this helps your needs.

Upvotes: 3

Related Questions