简体   繁体   中英

Wake Lock does not dim screen

I am writing an Android app, and would like to have my screen dim after acquiring a wake lock. However, my screen does not dim. It just continues (does not crash) as if nothing happened. I know the wake lock IS begin set because of some test code not shown here. The following is my code:

//Relevant declarations:
    PowerManager.WakeLock w1;
    PowerManager pm;

public void onClick(View view) {
pm = (PowerManager) getSystemService((Context.POWER_SERVICE));
w1 = pm.newWakeLock((PowerManager.SCREEN_DIM_WAKE_LOCK), "My Tag");
w1.acquire(); //DOES NOT DIM
}

public void onShake () {
if (w1.isHeld())
{
w1.release();
}

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

Any ideas? Thanks.

w1.acquire(); //DOES NOT DIM

If you are expecting it to immediately dim, that is not how it works. SCREEN_DIM_WAKE_LOCK does mean "change the current brightness to dim". It means "we need the screen to be at least dim". Anything else, such as using the device, can cause the screen to go to full brightness.

在清单中添加以下权限:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM