0

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...

Regsitration https://github.com/DrKLO/Telegram/blob/master/TMessagesProj/src/main/java/org/telegram/messenger/GcmRegistrationIntentService.java

@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) {

}
Antoine Murion
  • 773
  • 1
  • 14
  • 26
  • *Please kindly point out which parts i am wrong* I would migrate to FCM, it's a lot easier – Tim Jul 21 '16 at 08:12
  • Am I right that your concern is about the speed of the messages being received in some devices is your issue? There are a lot of factors that can affect [how long a push notification reaches a device](http://stackoverflow.com/q/37372685/4625829). With regards to codes, you should look into the [quickstart](https://github.com/googlesamples/google-services/tree/master/android/gcm) as reference. – AL. Jul 21 '16 at 11:11
  • Yes you are right. But the point is other apps are pushing the messages together on my device, only my app gets the notification after 10 mins. But if i delete the app and re-install again, then it would get the push message the same as other apps. So, i believe this should be my own problem as blamed by my boss. – Antoine Murion Jul 21 '16 at 15:59
  • @TimCastelijns: i tried the FCM project, but the same problem exists. The telegram app continues to deliver message on a timely manner, i really want to know the reason behind.. – Antoine Murion Jul 22 '16 at 04:17
  • How are you sending the messages? – Arthur Thompson Jul 22 '16 at 18:39
  • For FCM, i send the message through the testing page provided by Google. Only after 15-20mins, the FCM and GCM messages nearly arrive at the same time. I doubt the reason is the device lost connection with FCM/GCM server and it attempts to re-connect after a period of time. I guess if i would programmatically connect the device with GCM server again, it should solve the problem. – Antoine Murion Jul 25 '16 at 05:31
  • After another days of googling, I think my problem is v similar to this and i want to know would we force the re-connection to the gcm-network. Seem there are several people asked but there are no proper answers so far. http://stackoverflow.com/questions/18250188/do-gcm-ccs-upstream-messages-force-a-re-connection-to-the-gcm-network – Antoine Murion Jul 25 '16 at 06:50

0 Answers0