问题描述
我试图找出如何关闭屏幕从服务中。我已经读过this但我没有意识到如何从服务中做到这一点。我真的不希望处理唤醒锁,因为只要在屏幕熄灭,我真的不关心通过java code转回来。我只需要转动屏幕关闭一个时间的方法,我已经搜查永远在这。
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)创建一个虚拟活动
,并用它通过<$ C $获得窗口
对象C> getWindow(); 方法。然后,你会使用意图
从调用屏幕关闭你的服务
。
(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)使用 IHardwareService.Stub
。不属于SDK的,但有没有在这个博客帖子一个解决办法: HTTP: //www.tutorialforandroid.com/2009/01/changing-screen-brightness.html
(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:我会强烈建议第一个选项。你永远不知道什么时候一个类,不是SDK可能会改变的一部分。
这篇关于安卓:关闭屏幕从服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!