Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

google cloud messaging push with parse and android client does not work

used those lines in android:

InstanceID instanceID = InstanceID.getInstance(this);
        String token = null;


 token = instanceID.getToken(getString(R.string.gcm_defaultSenderId),
                        GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);

got exception , token=null.

google.android.gms.iid.InstanceID.getToken(Unknown Source)

any suggestions?

checked that sender id is ok and api key. no clue.

thanks

like image 301
joseph Avatar asked Nov 20 '25 06:11

joseph


1 Answers

I had this error as well. That was because I called instanceID.getToken in the main thread. The GCD guide says that: Do not call this method in the main thread; instead, use a service that extends IntentService.

Here there is a tutorial where is shown how create an IntentService where you can call instanceID.getToken. I hope this help.

like image 160
Flavio Reyes Avatar answered Nov 22 '25 02:11

Flavio Reyes



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!