Edited Summary
I am a bit frustrated on GCM as i am following Telegram and other sample projects to work it out. I believe it should be a standardized approach but i don't understand WHY ONLY MY APP RECEIVE GCM MESSAGES 10-15MINS LATER WHILE OTHER APPS PUSH MESSAGES AT THE SAME TIME ON SELECTED DEVICES.
My objective is clear and i want my push message arrives the same time as other applications (Not Whatsapp or Fb as they have their own cloud messaging tools). I wonder have i missed any important codes on the server side or the registration intent service.
Original Passage
Push service is important to my android application but I encounter problems on the reliability of GCM for my own app on selected devices.
I am following the approach used by Telegram in order to set the GCM. When I first register the application, GCM works perfectly well. However, after 15-20 minutes or i switch off the internet connection. GCM has problems on some of the devices (4 devices for testing, only Nexus continues to work while Samsung Galaxy S2, LG 4x and Sharp fail to work). However, after waiting for another ~20 minutes, the remaining devices receive the GCM messages.
Some people argue that GCM is extremely not reliable but it is written several years ago. In additions, telegram seems to use GCM but it works perfectly well on all my devices. It seems that there are problems with my own code. https://eladnava.com/google-cloud-messaging-extremely-unreliable/
Below are the codes of how to register the push and get the token. Please kindly point out which parts i am wrong...
@Override
protected void onHandleIntent(Intent intent) {
try {
InstanceID instanceID = InstanceID.getInstance(this);
final String token = instanceID.getToken(getString(R.string.gcm_defaultSenderId), GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
FileLog.d("tmessages", "GCM Registration Token: " + token);
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
ApplicationLoader.postInitApplication();
sendRegistrationToServer(token); //send to my own server
}
});
} catch (Exception e) { }
GcmInstanceIDListenerService https://github.com/DrKLO/Telegram/blob/master/TMessagesProj/src/main/java/org/telegram/messenger/GcmInstanceIDListenerService.java
@Override
public void onTokenRefresh() {
//I delete the original ID and get a new one
//
}
GcmPushListenerService https://github.com/DrKLO/Telegram/blob/master/TMessagesProj/src/main/java/org/telegram/messenger/GcmPushListenerService.java
@Override
public void onMessageReceived(String from, final Bundle bundle) {
}