Question

I want an Android service, which is listening for data (I have tried TCP and UDP) to wake up the service/phone when data arrives.

Currently the phone stays asleep when IP data arrives and that data is lost. Is this normal for Android? I see sleeps of 2+ hours several times a day, and 7+ hour sleeps when I am asleep.

Does GCM provided a solution which wakes up a service/phone when a message arrives.

I need messages to be displayed within a few seconds of them being sent from the server.

Can this only be achieved by keeping the CPU running all day long? Is there no interrupt from the GSM modem on the arrival of data?

Was it helpful?

Solution

As I understand it, if you have an outstanding socket connection over mobile data to a server, that socket connection is maintained while in sleep mode, and incoming packets will wake up the phone out of sleep mode (briefly) to deliver the data.

The same is not true of WiFi (and presumably not for hardwired Ethernet, either). You would need to hold a WakeLock and a WifiLock.

Does GCM provided a solution which wakes up a service/phone when a message arrives.

Yes, but...

I need messages to be displayed within a few seconds of them being sent from the server.

First, GCM has no service-level guarantee. I am not aware of any solution that does, including anything that you might roll yourself (e.g., MQTT).

Second, you have no idea if the device is capable of receiving any such messages (GCM or otherwise), as the device may be turned off, in airplane mode, etc.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top