Google Cloud Messaging注册TIMEOUT

时间:2015-09-19 20:14:03

标签: java android timeout google-cloud-messaging registration

我已经为我的应用程序选择了Google Cloud Messaging,到目前为止,它完全适用于Google API 17,18,19& 21.但是,在Google API 16上,我在注册级别获得了一个TIMEOUT。以前有人遇到过这个吗?我正在使用Google推荐的AsyncTask。

我的代码:

private class PrefetchData extends AsyncTask<Void, Void, Void> {

@Override
protected void onPreExecute() {
    super.onPreExecute();
    // before making http calls         
}

@Override
protected Void doInBackground(Void... arg0) {

try{

    // ...

    // register device to Google Cloud Messaging if not already done
    if(gcmDeviceRegID.equals("")){
        gcm = GoogleCloudMessaging.getInstance(getApplicationContext());
        gcmDeviceRegID = gcm.register(PROJECT_NUMBER);
    }

}

catch( Exception e ){
    e.printStackTrace();
    return null;
}

return null;

}

//...

日志:

W/InstanceID/Rpc(887): Found 10016
W/InstanceID/Rpc(887): No response android.os.ConditionVariable@41206630
W/System.err(887): java.io.IOException: TIMEOUT
W/System.err(887):  at com.google.android.gms.iid.zzc.zzb(Unknown Source)
W/System.err(887):  at com.google.android.gms.iid.zzc.zza(Unknown Source)
W/System.err(887):  at com.google.android.gms.iid.InstanceID.zzc(Unknown Source)
W/System.err(887):  at com.google.android.gms.iid.InstanceID.getToken(Unknown Source)
W/System.err(887):  at com.google.android.gms.gcm.GoogleCloudMessaging.register(Unknown Source)
W/System.err(887):  at com.domain.appname.SplashScreenActivity$PrefetchData.doInBackground(SplashScreenActivity.java:104)
W/System.err(887):  at com.domain.appname.SplashScreenActivity$PrefetchData.doInBackground(SplashScreenActivity.java:1)
W/System.err(887):  at android.os.AsyncTask$2.call(AsyncTask.java:287)
W/System.err(887):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
W/System.err(887):  at java.util.concurrent.FutureTask.run(FutureTask.java:137)
W/System.err(887):  at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
W/System.err(887):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)

如您所知,SplashScreenActivity.java:104就是这一行:

gcmDeviceRegID = gcm.register(PROJECT_NUMBER);

知道如何解决这个问题吗? 谢谢!

1 个答案:

答案 0 :(得分:1)

根据Arthur Thompson的评论,这是通过使用新推荐的方式注册到GCM(从2015年6月28日开始)来解决的:

             JSONObject datamsj = (JSONObject) args[0];
             try {
                    TimeZone tz = TimeZone.getTimeZone("UTC");
                    TimeZone tz2 = TimeZone.getTimeZone("America/Bogota");
                    Calendar cal = Calendar.getInstance(tz);
                    SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd yyyy HH:mm:ss zZ (z)");
                    sdf.setCalendar(cal);
                    cal.setTime(sdf.parse(datamsj.getString("fc")));

                    cal.setTimeZone(tz2);
                    Date date = cal.getTime();
                    DateFormat df = new SimpleDateFormat("HH:mm a");
                    messageTextDate = df.format(date);
                    messageText = datamsj.getString("msj");
                } catch (Exception e) {
                    e.printStackTrace();
                    return;
                }

而不是

InstanceID instanceID = InstanceID.getInstance(getApplicationContext());
gcmDeviceRegID = instanceID.getToken(PROJECT_NUMBER,GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);

有用的链接: https://developers.google.com/cloud-messaging/android/legacy-regid https://developers.google.com/cloud-messaging/registration

谢谢&amp;此致