Reputation: 1884
Any one have idea when i am sending the messages using the wifi network they are sent but i was not able to receive the same. Means wifi network will send the message but same network will not able to receive the message, on other side if i change my network to mobile data then its working fine.
Upvotes: 0
Views: 46
Reputation: 4950
Always check internet connection availability before running the application for push notification.
GCM works by keeping a long-lived socket open to Google's push notification server. The socket is kept open by sending "heartbeat" messages between the phone and server.
The network state may change and this socket will be broken (because the IP address of the device changes, from 3g to wifi, for example). If the message comes in before the socket is re-established, then the device will not immediately get the message.
The re-connection only happens when the phone notices the socket is broken, which only happens when it tries to send a heartbeat message.
You may check the network available like this:
private boolean isNetworkAvailable() {
ConnectivityManager connectivityManager
= (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
return activeNetworkInfo != null;
}
Here's where I get my answer: Google Cloud Messaging - messages sometimes not received until network state changed
Upvotes: 1