简体   繁体   English

Android:关闭服务屏幕

[英]Android: Turn off screen from a service

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. 我真的不想处理唤醒锁定,因为一旦屏幕关闭,我真的不关心通过java代码将其恢复。 I just need a one time method for turning the screen off and I have searched forever on this. 我只需要一次性关闭屏幕的方法,我就一直在搜索这个问题。

I see two options: 我看到两个选择:

(1) Create a dummy Activity and use it to get a Window object through the getWindow(); (1)创建一个虚拟Activity并使用它通过getWindow();获取一个Window对象getWindow(); method. 方法。 Then you would use an Intent to call the screen off from your Service . 然后,您将使用Intent从您的Service关闭屏幕。

(2) Use IHardwareService.Stub . (2)使用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 不是SDK的一部分,但是在这篇博客文章中有一个解决方法: 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. 你永远不知道什么时候不属于SDK的类可能会改变。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM