Android 2.2: Turning of screen under certain times of the day by code
I would like to know if there is any way to turn off the screen on an android device on for example 19.00-22.00 every day. I have some tablets running in kiosk mode, a开发者_如何转开发nd i want the screens to turn off when no one is using them and the store is closed.
Thanks
Screens will turn off automatically, if you have that set up properly in the device settings.
You can use AlarmManager
and a WakeLock
to arrange to keep the device screen awake during business hours. Have the AlarmManager
start up a service that acquires the WakeLock
and waits until closing time. You will need to use startForeground()
in the service to prevent Android from killing off your service.
In the real world, this implementation would suck, as it forces you to keep a service running all the time -- if you let the service shut down, you lose the WakeLock
and can never release()
it, so the screen will never shut off. So, outside of this sort of kiosk thing, I do not recommend this technique.
精彩评论