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.
Share
I see two options:
(1) Create a dummy
Activityand use it to get aWindowobject through thegetWindow();method. Then you would use anIntentto call the screen off from yourService.(2) Use
IHardwareService.Stub. Not part of the SDK, but there’s a workaround in this blog post: https://web.archive.org/web/20210224163252/http://www.tutorialforandroid.com/2009/01/changing-screen-brightness.htmlBTW: I would strongly recommend the first option. You never know when a class that is not part of the SDK might change.