Monday, October 21, 2013

Tell when Android device is in sleep mode

Is there a way to tell when an Android device is in sleep mode? When testing my app, I press the power button to turn off the screen & need to wait until sleep mode is active. I then send messages to my device using Google Cloud Messaging (GCM) & then play a sound & notification once it arrives. But if I send this message before sleep mode is active, then I am not sure whether it received the message because it was still alive or because my service routine received started by the GCM broadcast receiver.

You can find out when the screen goes off using android.intent.action.SCREEN_OFF intent yet there is no Intent to find out with certainty if the device is in sleep mode as far as I know.

No comments:

Post a Comment