安卓:关闭屏幕从服务 [英] Android: Turn off screen from a service

查看:151
本文介绍了安卓:关闭屏幕从服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出如何关闭屏幕从服务中。我已经读过<一个href="http://stackoverflow.com/questions/1875669/calling-hidden-api-in-android-to-turn-screen-off">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可能会改变的一部分。

这篇关于安卓:关闭屏幕从服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆