سؤال

I turn the screen off when the right command appear.

TURN OFF SCREEN:

    WindowManager.LayoutParams params = getWindow().getAttributes();
    params.flags |= LayoutParams.FLAG_KEEP_SCREEN_ON;
    params.screenBrightness = 0.0f;
    getWindow().setAttributes(params);

This is working fine. At least it seems like that.

But when the command comes to turn the screen on, it doesn't work. This is the code for turn on:

TURN ON SCREEN:

    WindowManager.LayoutParams on = getWindow().getAttributes();
    on.screenBrightness = 0.7f;
    getWindow().setAttributes(on);

The brightness doesn't get up. And I don't know why.

But when I change the screenBrightness at TURN OFF SCREEN to params.screenBrightness = 0.1f; then the brightness of the screen is not quite black but its very low. And if it's 0.1f I can call the BrightnessUp function and the brightness of the screen go on right level.

All in all I can't set the brightness higher if it's 0.0f before, only if it's 0.1f or higher.

I also tried this solution to turn of the screen:

    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    screenWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,   "screenWakeLock");
    screenWakeLock.acquire();

Manifest:

<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.DEVICE_POWER"/>

But this doesn't work anyway.

So I hope there is anybody out there to help me and give me a solution for this problem.

هل كانت مفيدة؟

المحلول

Ok I solved my problem.

I just set the screenBrightness in TURN OFF SCREEN params.screenBrightness=0.01f; and then all work fine.

The screen is black if it should turn off and it get the right brightness if it should on again.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top