Reputation: 65
I've chosen Google Cloud Messaging for my application, which is so far working perfectly on Google APIs 17,18, 19 & 21. However, on Google APIs 16, I get a TIMEOUT at registration level. Has anyone faced this before ? I am using an AsyncTask as recommended by Google.
My code:
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;
}
//...
The log:
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)
As you understand, SplashScreenActivity.java:104 is this line:
gcmDeviceRegID = gcm.register(PROJECT_NUMBER);
Any idea how to solve this? Thanks!
Upvotes: 1
Views: 3620
Reputation: 65
As per Arthur Thompson's comment, this is being solved by using the new recommended way to register to GCM (starting from 2015, June 28):
InstanceID instanceID = InstanceID.getInstance(getApplicationContext());
gcmDeviceRegID = instanceID.getToken(PROJECT_NUMBER,GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
instead of
gcm = GoogleCloudMessaging.getInstance(getApplicationContext());
gcmDeviceRegID = gcm.register(PROJECT_NUMBER);
Useful links: https://developers.google.com/cloud-messaging/android/legacy-regid https://developers.google.com/cloud-messaging/registration
Thanks & Regards
Upvotes: 1