How can I keep my screen on using a background running app?

杀马特。学长 韩版系。学妹 提交于 2019-12-13 03:57:45

问题


I need to make an app that keeps the screen on even when the app is running in the background.

I've tried:

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

But it only works when the app is running and can't run as a service.

I've also tried wakelocks but SCREEN_BRIGHT_WAKE_LOCK and FULL_WAKE_LOCK have both been deprecated. The only wakelock left is PARTIAL_WAKE_LOCK.

Is there someway to keep the screen on using the PARTIAL_WAKE_LOCK, ACQUIRE_CAUSES_WAKEUP, and some loops?

Frankly I have no real experience with Java or app development and I've been assigned this task as an intern so any help would be appreciated.


回答1:


The response is no, you can't. As you said the only way of doing that is using deprecated api. As alternative you could use an activity with transparent theme but if the user for example press the home button and the activity is no more in foreground you loose anyway.



来源:https://stackoverflow.com/questions/24291770/how-can-i-keep-my-screen-on-using-a-background-running-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!