0

I try of update my app, but i show me error when the appa should be generated the token. my app show me token not generated.

my firebase code is the follow:

import android.util.Log;
import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.FirebaseInstanceIdService;

public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {

    private static final String TAG = "MyFirebaseIIDService";

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

    private void storeToken(String token) {
        //saving the token on shared preferences
        SharedPreference.getInstance(getApplicationContext()).saveDeviceToken(token);
    }
}

I rencently migrated to AndroidX, and i dont know what happpen with my code thnks

i try with this, but not work, token i not generated

import android.util.Log;

import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.messaging.FirebaseMessagingService;

public class MyFirebaseInstanceIDService extends FirebaseMessagingService {

    private static final String TAG = "MyFirebaseIIDService";




    @Override
    public void onNewToken(String token) {
        super.onNewToken(token);
        String refreshedToken = FirebaseInstanceId.getInstance().getToken();
        Log.d(TAG, "Refreshed token: " + refreshedToken);
        storeToken(refreshedToken);
    }

    private void storeToken(String token) {
        //saving the token on shared preferences
        SharedPreference.getInstance(getApplicationContext()).saveDeviceToken(token);
    }
}
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Matteo
  • 19
  • 7
  • look for this answer : https://stackoverflow.com/questions/37451395/firebase-ontokenrefresh-is-not-called – haresh Jan 23 '20 at 01:40
  • have you defined it in manifest if yes then try to reconnect it with firebase using assistant or check if the service is starting. Post the error that you are getting – Amanpreet Kaur Jan 23 '20 at 04:21
  • no need to do this String refreshedToken = FirebaseInstanceId.getInstance().getToken(); token is automatically generated in the method – Amanpreet Kaur Jan 23 '20 at 04:30

1 Answers1

1

please look at this

public class MyFirebaseInstanceIDService extends FirebaseMessagingService {

    private static final String TAG = "MyFirebaseIIDService";

    @Override
    public void onNewToken(String token) { // this is the "token"
        super.onNewToken(token); 
        storeToken(token);
    }

    private void storeToken(String token) {
        //saving the token on shared preferences
        SharedPreference.getInstance(getApplicationContext()).saveDeviceToken(token);
    }
}

Please try this code.

Hope this will help!

Rahul Gaur
  • 1,661
  • 1
  • 13
  • 29