问题
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