Raghul Sugathan
Raghul Sugathan

Reputation: 370

Android Firebase notification "OnTokenRefresh" not getting called

I am working on a project in which Firebase notification is being used. I am facing an issue of not receiving notification after some hours of application installation. Initially notifications are received as expected but later not working as intended.

I am unable to identify the cause of this issue.

@Override  public void onTokenRefresh()

above method is used inside a service class (FCMIDService) for token refresh of firebase and using the latest token for future use of notification.

<service android:name=".services.fcm.FCMIDService"><intent-filter> <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/></intent-filter> </service>

Any help should be greately appreciated.

Upvotes: 0

Views: 1090

Answers (2)

kunwar97
kunwar97

Reputation: 825

Add this line in your Home Activity to get the latest token every time when the app restarts.

String token = FirebaseInstanceId.getInstance().getToken();

Upvotes: 0

AskNilesh
AskNilesh

Reputation: 69689

onTokenRefresh in FirebaseInstanceIdService is only called when a new token is generated. If your app was previously installed and generated a token then onTokenRefresh would not be called. Try uninstalling and reinstalling the app to force the generation of a new token, this would cause onTokenRefresh to be called.

make sure that t your FirebaseInstanceIdService is properly defined in your AndroidManifest.xml like this

<service
    android:name="com.bnt.etailers.fcm.MyFireBaseInstanceIDService"
    android:exported="false">
    <intent-filter>
        <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
    </intent-filter>
</service>

<service
    android:name="com.bnt.etailers.fcm.GCMNotificationIntentService"
    android:exported="false">
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT" />
    </intent-filter>
</service>

Upvotes: 3

Related Questions