Firebase Cloud Messaging not calling FirebaseInstanceId
Solution 1
Thanks Endanke for figuring this out with me. It seems that the Firebase documentation is inconsistent. One page says your intent filter in your manifest file should be INSTANCE_ID_EVENT
, and another says INSTANCEID_EVENT
.
You should use INSTANCE_ID_EVENT
, and once you make the change, you'll need to completely uninstall and reinstall your app for the changes to kick in.
Solution 2
FCM should be used as a replacement to GCM. In your case it looks like you have services for both FCM and GCM in your manifest. Try remove the gcm.GcmService, and only use the one that extends FirebaseInstanceId.
Solution 3
After a ton of trial and error my issue was having tools:node="replace" in my application tag...removing it solved the issue for me
Related videos on Youtube
qwertz
Updated on June 04, 2022Comments
-
qwertz almost 2 years
I just updated GCM to FCM according to this guide here. The site says my service which extends FirebaseInstanceIdService will be called as soon as the token is generated. For some reason, my service is never called and
onTokenRefresh
is never executed.My services are registered like this, according to the guide:
<service android:name=".fcm.FcmService"> <intent-filter> <action android:name="com.google.firebase.MESSAGING_EVENT"/> </intent-filter> </service> <service android:name=".fcm.InstanceIdService"> <intent-filter> <action android:name="com.google.firebase.INSTANCEID_EVENT"/> </intent-filter> </service>
My service:
public class InstanceIdService extends FirebaseInstanceIdService { private static final String TAG = "InstanceIdService"; @Override public void onTokenRefresh() { String token = FirebaseInstanceId.getInstance().getToken(); Log.e(TAG, "Got token: " + token); } }
The LogCat doesn't say anything about missing configuration files or else, and I can see logs about FirebaseApp and a Log entry mentioning the token, but still my service is never called.
Do I need to start this service somewhere in my activity? Am I doing something wrong? Can someone guide me in the correct direction?
EDIT: using
Log.e("TOKEN", "Token: " + FirebaseInstanceId.getInstance().getToken());
correctly prints my token, so that means it was generated successfully. The service still doesn't get called...EDIT 2: Changing INSTANCEID_EVENT to INSTANCE_ID_EVENT fixed the issue, although I had to reinstall the app. As I already released a beta version containing the new FCM, my beta testers won't be able to subscribe to the topics to reveice incoming messages. So how should I solve that?
-
Zach Rattner almost 8 yearsFor what it's worth, one doc (firebase.google.com/docs/cloud-messaging/android/…) says the intent filter should be
INSTANCE_ID_EVENT
and another (developers.google.com/cloud-messaging/android/…) saysINSTANCEID_EVENT
. Neither seem to be working for me -- I have the same issue as you. -
Endanke almost 8 years@ZachRattner That did it for me, nice catch! Make sure you reinstall your app after the change.
-
hordurh almost 8 yearsI can confirm that INSTANCE_ID_EVENT worked for me but not INSTANCEID_EVENT
-
-
qwertz almost 8 yearsBut where should I receive the incoming messages when I remove gcm.GcmService?
-
Arthur Thompson almost 8 yearsIn your extension of FirebaseMessageService you would add a service for that as well
-
qwertz almost 8 yearsSorry forgot to rename the GcmService, but it already extends FirebaseMessagingService
-
Arthur Thompson almost 8 yearsHave you tried uninstalling and reinstalling your app, you would only get the token generation callback when a new token is generated. If the app already had a token then no new token would be used. Uninstalling and reinstalling will force the generation of a new token.
-
natsumiyu almost 8 yearsI already done this but it still doesn't call
onTokenRefresh()
-
vabhi vab over 7 yearsThe think uninstall externally and re-run worked for me. Thank you.
-
SimpleJ over 5 yearsIs this answer still correct? Neither of the pages you linked include
INSTANCEID_EVENT
orINSTANCE_ID_EVENT
in their text.