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)
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With