Search code examples
androidfirebasegoogle-cloud-messaging

Firebase Cloud Messaging not calling FirebaseInstanceId


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?


Solution

  • 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.