Google Cloud Messaging - messages sometimes not received until network state changed

后端 未结 5 1807
我寻月下人不归
我寻月下人不归 2020-11-28 04:40

While working on a little project that integrates with GCM, I\'ve stumbled across a bit of a strange issue.

Some times when I start watching the log to see if messag

5条回答
  •  醉酒成梦
    2020-11-28 05:31

    so, If @theelfismike thinking is true, may I use something like:

      ConnectivityManager cm = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
    
        NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
        if (null != activeNetwork) {
            if(activeNetwork.getType() == ConnectivityManager.TYPE_WIFI)
               // here the network changed to Wifi so I can send a heartbeat to GCM to keep connection
    
            if(activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE)
              //here the network changed to mobileData so I can send a heartbeat to GCM to keep connection
        }
    

    is my solution good?

提交回复
热议问题