GCM msg delivery times are WILDLY erratic

前端 未结 5 853
后悔当初
后悔当初 2020-12-03 03:40

I\'ve setup an Android app with GCM support, and have a little test app to send a msg to the app. When I run the App in the emulator, I can see (via logging msgs) that it re

5条回答
  •  不思量自难忘°
    2020-12-03 04:22

    This matter is important to me.

    I have set up this code inside a one second timer Handler to send out a GCM message every 2 minutes. The hope is that it will keep things alive

                if ((mOneSecondTick %120) == 0){
                // q 1 minute check when we got last call....
                long lDiff = System.currentTimeMillis() - GCMlastCall;
                if (PushAndroidActivity.GCMAvailable){
                    Log.d("pushAndroidActivity",String.format("(mOneSecondTick %d",lDiff));
                    if (lDiff > 122 * 1000){ // more than a minute
                        Intent intent = new Intent(StayInTouch.this,PushAndroidActivity.class);
                        2startActivity(intent);
                    }else{ // every 2 minutes send out a gcm message...
                        asyncWebCall(String.format(AgeingLib.GCMTICKLE,androidid),0);
                        return; // only if it sends a tickle and all is well...
                    }
                }else{
                    Log.d("pushAndroidActivity",String.format("(mOneSecondTick mod60 no GCM on this device"));
                }
            }
    

    GCMlastCall is the last time a message was received, so we can tell if gcm stopped.

    Been working for a couple of days now seems OK

提交回复
热议问题