FirebaseInstanceId does not exist anymore
Solution 1
add the following to the build.gradle file:
implementation 'com.google.firebase:firebase-messaging:17.0.0'
implementation 'com.google.firebase:firebase-core:16.0.0'
more info here:
https://firebase.google.com/docs/cloud-messaging/android/client#set-up-firebase-and-the-fcm-sdk
Solution 2
I also faced the same problem. From the doc, it says FirebaseInstanceId is no longer available and says to use FirebaseMessaging.getInstance().token as below
FirebaseMessaging.getInstance().token.addOnCompleteListener(OnCompleteListener { task ->
if (!task.isSuccessful) {
Log.w(TAG, "Fetching FCM registration token failed", task.exception)
return@OnCompleteListener
}
// Get new FCM registration token
val token = task.result
})
Solution 3
I was also facing the same problem. Actually, FirebaseInstanceId has been shut down, replaced with Firebase Installation.
Try:
FirebaseInstallations.getToken();
Solution 4
Add into Gradle:
implementation 'com.google.firebase:firebase-messaging:22.0.0'
implementation 'com.google.firebase:firebase-core:19.0.0'
Then add the following code to get the token:
public static String returnMeFCMtoken() {
final String[] token = {""};
FirebaseMessaging.getInstance().getToken().addOnCompleteListener(new OnCompleteListener<String>() {
@Override
public void onComplete(@NonNull Task<String> task) {
if(task.isComplete()){
token[0] = task.getResult();
Log.e("AppConstants", "onComplete: new Token got: "+token[0] );
}
}
});
return token[0];
}
Related videos on Youtube
Joan P.
Updated on May 21, 2022Comments
-
Joan P. about 2 years
I just did an upgrade to all my Firebase dependencies and I have an issue,
FirebaseInstanceId
is not recognized anymore. I have used it to get the token id like this:String tokenId = FirebaseInstanceId.getInstance().getToken();
This is the error:
Cannot resolve symbol 'FirebaseInstanceId'
Here is my build.gradle file:
//Firebase implementation 'com.google.firebase:firebase-auth:16.0.1' implementation 'com.google.firebase:firebase-database:16.0.1' implementation 'com.google.firebase:firebase-firestore:17.0.1' //FirebaseUI implementation 'com.firebaseui:firebase-ui-auth:4.0.0' implementation 'com.firebaseui:firebase-ui-database:4.0.0' implementation 'com.firebaseui:firebase-ui-firestore:4.0.0'
How can I get the token id using the latest dependencies?
-
Eshiet almost 3 yearsFirebaseMessaging.getInstance().getToken() is an asynchronous call, so return token[0] would return "". you need a way to wait for the response