Firebase Ontokenrefresh() Is Not Called

Firebase onTokenRefresh() is not called

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.

Also be sure that your FirebaseInstanceIdService is properly defined in your AndroidManifest.xml

In your Manifest File.

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

FirebaseInstanceIdService class

public class MyFireBaseInstanceIDService extends FirebaseInstanceIdService {

private static final String TAG = MyFireBaseInstanceIDService.class.getSimpleName();

@Override
public void onTokenRefresh() {
// Get updated InstanceID token.
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
Log.d(TAG, "Refreshed token: " + refreshedToken);

if (refreshedToken!=null) {
SettingPreferences.setStringValueInPref(this, SettingPreferences.REG_ID, refreshedToken);
}
// TODO: Implement this method to send any registration to your app's servers.
sendRegistrationToServer(refreshedToken);
}
// [END refresh_token]

/**
* Persist token to third-party servers.
*
* Modify this method to associate the user's FCM InstanceID token with any server-side account
* maintained by your application.
*
* @param token The new token.
*/
private void sendRegistrationToServer(String token) {
// Add custom implementation, as needed.
}}

FirebaseMessagingService class.

public class GCMNotificationIntentService extends FirebaseMessagingService {
// Sets an ID for the notification, so it can be updated

public GCMNotificationIntentService() {
super();
}

@Override
public void onMessageReceived(RemoteMessage message) {

}}

Firebase OnTokenRefresh() never called?

Update your dependencies to com.google.firebase:firebase-core:11.0.4 com.google.firebase:firebase-messaging:11.0.4.

onTokenRefresh() is never called on first app install

This problem can occur when the device or emulator is running an old version of Google Play Services that is not compatible with the version of the Firebase libraries used. When this condition exists, the logcat will contain this warning message:

W/GooglePlayServicesUtil: Google Play services out of date.  Requires XXXXXXXX but found XXXXXXXX

The solution is to update Google Play Services, or downgrade the version of Firebase.

Because the Firebase APIs require a compatible version of Google Play Services, it's good practice to confirm the presence of a compatible version during app initialization using GoogleApiAvailability.

Firebase Notifications integration onTokenRefresh not getting called

This receiver will only be triggered/called when to token is refreshed. For initial registration you need to explicitly call the registration method.

The app needs to call the below method to get the push token. Token will not be generated on its own

FirebaseInstanceId.getInstance().getToken()

Refer to the official example for more details. Exact code snippet



Related Topics



Leave a reply



Submit