Keep screen on in Activity - does not work with FLAG_KEEP_SCREEN_ON

跟風遠走 提交于 2019-12-04 05:10:36

i was facing same problem, i was using one activity for my project and all the other screen are fragments then i used the android:keepScreenOn="true" in main activity.

please try to use this and let me know if you didn't get your desire result.

Thanks.

Only solution which realy works in my app is WakeLock in main application class. Unfortunately the SCREEN_BRIGHT_WAKE_LOCK flag is deprecated!

public class MyApp extends Application {
    PowerManager.WakeLock screenOnWakeLock;
    @Override
    public void onCreate() {
        super.onCreate();
        PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
        wakeLock =  powerManager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,"ScreenlockTag");
        wakeLock.acquire();
    }

    @Override
    public void onTerminate()
    {
        if (screenOnWakeLock != null && screenOnWakeLock.isHeld())
            screenOnWakeLock.release();
        super.onTerminate();
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!