How can I keep my screen on using a background run

2019-08-27 11:01发布

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条回答
Juvenile、少年°
2楼-- · 2019-08-27 11:23

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.

查看更多
登录 后发表回答