Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FirebaseInstanceId does not exist anymore

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?

like image 897
Joan P. Avatar asked May 29 '18 08:05

Joan P.


1 Answers

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
})
like image 189
Soe Thiha Avatar answered Oct 06 '22 09:10

Soe Thiha