简体   繁体   中英

switch off/on screen on PARTIAL_WAKE_LOCK

I'm using this code to enter in PARTIAL_WAKE_LOCK mode:

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

but I do not succeed to switch off the screen and switch on when I need it,I read tens of examples without succeed in it.

I can't use code that require the permission DEVICE_POWER like goToSleep() and wakeUp().

My goal is switch on the screen for 1 second and to switch off it for 10 seconds, and then start again.

Thanks all.

The use of PowerManager requires DEVICE_POWER permission that is only for applications that are signed by the same signature was used to sign the firmware. That is why you cannot use goToSleep() and wakeUp().

This code worked for me to turn on/off the screen:

//Turn off - brighness to 0;            
WindowManager.LayoutParams params = getWindow().getAttributes();
params.flags |= LayoutParams.FLAG_KEEP_SCREEN_ON;
params.screenBrightness = 0;
getWindow().setAttributes(params);

To turn on just change the brighness to >0;

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