Home » Android » firebase – FCM Token is not generating in some android devices

firebase – FCM Token is not generating in some android devices

Posted by: admin June 15, 2020 Leave a comment


I was having issues in GCM, so i migrates to FCM but I am still getting issues related to token.

I launched my updated app and I checked that there is 300 new users,
200 of them are getting tokens and 100 are not getting any token, it’s a very critical issue.

Any Solutions of null token?

How to&Answers:

You get your FCM token from MyInstanceIDListenerService class onTokenRefresh() method on every fresh installation.

Or you can also get FCM token with this line of code:



     class MyFirebaseInstanceIdService extends FirebaseInstanceIdService {

            private static final String TAG = "MyFirebaseIIDService";

            public void onTokenRefresh() {

                //Getting registration token
                String refreshedToken = FirebaseInstanceId.getInstance().getToken();

                //Displaying token in logcat
                Log.e(TAG, "Refreshed token: " + refreshedToken);


            private void sendRegistrationToServer(String token) {
                //You can implement this method to store the token on your server
                //Not required for current project

     **Sometimes tokens are not generated then write this code**

public class ContCreateTokenService extends Service {
            public IBinder onBind(Intent intent) {
                return null;

            public int onStartCommand(Intent intent, int flags, int startId) {
                Intent serviceIntent = new Intent(this, MyFirebaseMessagingService.class);
                return START_REDELIVER_INTENT;

public class FetchNewRefreshToken extends IntentService {
     * Creates an IntentService.  Invoked by your subclass's constructor.
     * @param name Used to name the worker thread, important only for debugging.

    public static final String TAG = FetchNewRefreshToken.class.getSimpleName();

    public FetchNewRefreshToken() {

    protected void onHandleIntent(Intent intent) {
        try {

            // Resets Instance ID and revokes all tokens.

            // Now manually call onTokenRefresh()
            Log.e(TAG, "Getting new token");
        } catch (Exception e) {

Also add it in Menifest file

 <service android:name=".ContCreateTokenService" />
 <service android:name=".FetchNewRefreshToken " />

In splash Activity : –

 startService(new Intent(this, FetchNewRefreshToken.class));
 startService(new Intent(this, ContCreateTokenService.class));