Skip to content
This repository has been archived by the owner on Sep 4, 2020. It is now read-only.

InstanceID.getToken() not called in an Intent #354

Closed
alexislg2 opened this issue Nov 18, 2015 · 7 comments
Closed

InstanceID.getToken() not called in an Intent #354

alexislg2 opened this issue Nov 18, 2015 · 7 comments
Assignees
Labels

Comments

@alexislg2
Copy link
Contributor

Hey, I'm having a look at the PushInstanceIDListenerService.java file. And this line throw an exception on my logcat errors

String token = InstanceID.getInstance(getApplicationContext()).getToken(senderID, GCM);

Error on logcat is E PushPlugin_PushInstanceIDListenerService: at com.google.android.gms.iid.InstanceID.getToken(Unknown Source)

According to the official documentation and to this SO post http://stackoverflow.com/questions/30577978/google-cloud-messaging-push-with-parse-and-android-client-does-not-work this line should be called in an Intent Do not call this method in the main thread; instead, use a service that extends IntentService.

This could explain why I never receive new tokens on my backend after token refresh.

this sample gives the right way to do it. What do you think?
https://github.com/googlesamples/google-services/blob/master/android/gcm/app/src/main/java/gcm/play/android/samples/com/gcmquickstart/MyInstanceIDListenerService.java

@macdonst macdonst added the bug label Nov 18, 2015
@macdonst macdonst self-assigned this Nov 18, 2015
@macdonst
Copy link
Member

@alexislg2 thanks for the heads up and investigation. I was basing PushInstanceIDListenerService off a sample from Google that called the method directly. I'll make the change shortly.

@alexislg2
Copy link
Contributor Author

Great!

I'm not sure if you know but if you want to test the receiver you can type
adb shell am startservice -a com.google.android.gms.iid.InstanceID --es "CMD" "RST" -n $PACKAGE_ID/com.adobe.phonegap.push.PushInstanceIDListenerService

where $PACKAGE_ID is the Android package name. You will have to add the @Override decorator over the onTokenRefresh method + set permission to android:exported="true" in AndroidManifest.xml

@alexislg2
Copy link
Contributor Author

I'll make a PR

@macdonst
Copy link
Member

@alexislg2 have you done the work yet? If not this is on my list to get done today.

@alexislg2
Copy link
Contributor Author

yeah just wait a few seconds ;)

@macdonst
Copy link
Member

Awesome, thanks @alexislg2. I've merged the PR and will do a point release sometime today. You saved me a couple hours of work to be sure. Open source folks, it's awesome.

@lock
Copy link

lock bot commented Jun 5, 2018

This thread has been automatically locked.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 5, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

2 participants