In my MainActivity
in my log, I can see the token using FirebaseInstanceId.getInstance().getToken()
and it display the generated token. But it seems like in my MyFirebaseInstanceIDService
where it is extends to FirebaseInstanceIdService
, the onTokenRefresh()
is not called, where in this function it was said that the token is initially generated here. I needed to call sendRegistrationToServer()
that's why I'm trying to know why it doesn't go in the onTokenRefresh()
.
Here is my code
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);
}
}
Reinstalling did the trick for me!
Also be sure that your FirebaseInstanceIdService is properly defined in your AndroidManifest.xml
In your Manifest File.
FirebaseInstanceIdService class
FirebaseMessagingService class.
Try re-install the app, by uninstall it first from your device or emulator. It will then generate a new token, thus onTokenRefresh() will be called again.
In my case, I tried everything but
onTokenRefresh
was never called. Then I change my WiFi and I connect to different network, Now it worked!!. Previous WiFi has good internet connectivity, Don't know why it was happening. May be this can help someone.Yes this might happen some times.
Please call the following method wherever you want to get your fcm id.
In my case I forgot to add internet permission in manifest,
Hope most people won't make this mistake.