简体   繁体   中英

How to keep the screen lit in later versions of the kitkat API?

I am making an APP that keeps the smartphone screen lit, even when the APP is minimized .

I'm using a class with extends Service to do this, in onCreate I put the code that keeps the screen always lit:

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "watever");
    wl.acquire();

Android Studio gives me an alert: FULL_WAKE_LOCK is deprecated
But I have not figured out how to do it the current way.

This code is only working until KitKat .
In Lollipop or later, it does not show any error, but does not work.

The goal is to keep the screen lit even with the minimized APP .

This APP , for example, does this way: https://play.google.com/store/apps/details?id=com.brilliant.apps.screenon

大多数应用程序应该使用FLAG_KEEP_SCREEN_ON而不是这种类型的唤醒锁,因为当用户在应用程序之间移动时,平台将正确管理它,并且不需要特殊权限。

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