Android: Turn off screen from a service

家住魔仙堡 提交于 2019-12-07 06:13:36

问题


I am trying to figure out how to turn off the screen from within a service. I have already read this but I am failing to realize how to do this from within a service. I don't really want to deal with wake locks because as soon as the screen goes off, I don't really care about turning it back via java code. I just need a one time method for turning the screen off and I have searched forever on this.


回答1:


I see two options:

(1) Create a dummy Activity and use it to get a Window object through the getWindow(); method. Then you would use an Intent to call the screen off from your Service.

(2) Use IHardwareService.Stub. Not part of the SDK, but there's a workaround in this blog post: http://www.tutorialforandroid.com/2009/01/changing-screen-brightness.html

BTW: I would strongly recommend the first option. You never know when a class that is not part of the SDK might change.



来源:https://stackoverflow.com/questions/5917192/android-turn-off-screen-from-a-service

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