I tried to reinstall my application multiple times, I noticed that just about 4 from 10 times that the onTokenRefresh() is called (log output)
public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {
@Override
public void onTokenRefresh() {
// Get updated InstanceID token.
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
Log.d(TAG, "Refreshed token: " + refreshedToken);
sendRegistrationToServer(refreshedToken);
}
}
Is there any way to guarantee that onTokenRefresh() to be called so the application will be subscribed to a topic when there is a good internet connection,something like launching a Service that check every time whether the application has subscribed to a topic,if not, relaunching firebase service.
In onCreate() function I did :
mRegistrationBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// checking for type intent filter
if (intent.getAction().equals(Config.REGISTRATION_COMPLETE)) {
// gcm successfully registered
// now subscribe to `global` topic to receive app wide notifications
FirebaseMessaging.getInstance().subscribeToTopic(Config.TOPIC_GLOBAL);
} else if (intent.getAction().equals(Config.PUSH_NOTIFICATION)) {
// new push notification is received
}
}
};