Search code examples
androidservicewakelock

Detect Device Wakeness In Android


I'm trying to create a service that run in background in android.. That service should work only when the device is on sleep (Means that screen is off)..

I think that can be done using a service but I don't know how to detect if the phone is awake or not.. Any Idea ? Thanks..


Solution

  • For screen on-off state, you can try with ACTION_SCREEN_ON and ACTION_SCREEN_OFF intents, as shown in this blog post:

    http://thinkandroid.wordpress.com/2010/01/24/handling-screen-off-and-screen-on-intents/

    From here : How to detect whether screen is on or off if API level is 4?