Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android GCM InstanceId.getToken() -> java.io.IOException: TIMEOUT

i'm trying to implement push notifications in my android app but i'm currently stuck at the point of receiving a token.

I'm using the latest method of "InstanceID" and followed some examples. I've added the permissions and the services to my Manifest ( and added the code for them aswell ) but whatever i try, i always get the "java.io.IOException: TIMEOUT" error. I've tried different phones, wifi, Lte and 3G but nothing seems to change anything.

I never got to the error saying "SERVICE_NOT_AVAILABLE". Only stuck at this one.

Manifest

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<receiver
  android:name="com.google.android.gms.gcm.GcmReceiver"
  android:exported="true"
  android:permission="com.google.android.c2dm.permission.SEND" >
  <intent-filter>
      <action android:name="com.google.android.c2dm.intent.RECEIVE" />
        <category android:name="de.company.appname" />
  </intent-filter>
</receiver>
<service
  android:name="de.company.gcm.ModuleGCMListenerService"
  android:exported="false" >
  <intent-filter>
     <action android:name="com.google.android.c2dm.intent.RECEIVE" />
  </intent-filter>
</service>
<service
  android:name="de.company.gcm.ModuleInstanceIDListenerService"
  android:exported="false">
  <intent-filter>
    <action android:name="com.google.android.gms.iid.InstanceID"/>
  </intent-filter>
</service>

InstanceID call:

try 
{
  token = instanceID.getToken(
            senderId,
            GoogleCloudMessaging.INSTANCE_ID_SCOPE, 
            null);
} 
catch (IOException e) 
{
  e.printStackTrace();
}

instanceID.getId() is working.

W/InstanceID/Rpc: No response android.os.ConditionVariable@129d5713
W/System.err: java.io.IOException: TIMEOUT
W/System.err:   at com.google.android.gms.iid.zzc.zzb(Unknown Source)
W/System.err:   at com.google.android.gms.iid.zzc.zza(Unknown Source)
W/System.err:   at com.google.android.gms.iid.InstanceID.zzc(Unknown Source)
W/System.err:   at com.google.android.gms.iid.InstanceID.getToken(Unknown Source)
like image 382
Benni Avatar asked Oct 28 '15 08:10

Benni


1 Answers

I finally figured out my problem when searching for similar errors at the same position in the code.

New GCM API Register Unknown Source Error

In this case the Error "MAIN_THREAD" is indeed a bit more obvious.

So it was because the InstanceId.getToken() can't be called in the Main Thread.

Though it didn't work with the new AsyncTask<Void, Void, Void>() method as suggested in the Google Github Examples.

I had to use

new Thread(new Runnable() {
    public void run() {
        //code
    }
}).start();
like image 53
Benni Avatar answered Oct 21 '22 15:10

Benni