0

I have tried the following code:

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

However, it only works when the program is on screen.

My app will launch Chrome to visit a website and it becomes background. At this time, it doesn't work.

If I want to keep the screen on when I launch my app, even though it may be at background, how can I do to implement it?

4

1 回答 1

0

尝试创建一个扩展服务的类,然后添加

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

即使您的应用不在屏幕上,它也会在后台运行。您也可以使用唤醒锁。你可以在这里看到一个很好的教程。

于 2013-10-18T02:20:04.797 回答