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 and need to wait until sleep mode is active. I then send messages to my device using Google Cloud Messaging (GCM) and then play a sound and notification once it arrives. But if I send this message before sleep mode is active, then I am not sure whether it got the message because it was still alive or because my service routine got started by the GCM broadcast receiver.
You can find out when the screen goes off using android.intent.action.SCREEN_OFF
intent but there is no Intent to find out with certainty if the device is in sleep mode as far as I know.