Android: Firebase token is null at first run

The token is fetched asynchronously on first app start. You have to wait for onTokenRefresh() to be called in your FirebaseInstanceIdService before the token can be accessed.


uninstall the app from emulator and run again , so that the onTokenRefreshed method will be called again .

To check wether you are already registered and you just want to know the FCM TOken

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

add the above line in MyFirebaseMessagingService class any where(in oncreate method ) and just Toast or log the refreshedToken.


Just replace:

String token = instanceID.getToken();

with:

String token = instanceID.getToken($SENDER_ID, "FCM");

and it will work.