FirebaseInstanceIdService is deprecated

后端 未结 10 2297

Hope all of you aware of this class, used to get notification token whenever firebase notification token got refreshed we get the refreshed token from this class, From follo

10条回答
  •  [愿得一人]
    2020-11-22 10:21

    Simply call this method to get the Firebase Messaging Token

    public void getFirebaseMessagingToken ( ) {
            FirebaseMessaging.getInstance ().getToken ()
                    .addOnCompleteListener ( task -> {
                        if (!task.isSuccessful ()) {
                            //Could not get FirebaseMessagingToken
                            return;
                        }
                        if (null != task.getResult ()) {
                            //Got FirebaseMessagingToken
                            String firebaseMessagingToken = Objects.requireNonNull ( task.getResult () );
                            //Use firebaseMessagingToken further
                        }
                    } );
        }
    

    The above code works well after adding this dependency in build.gradle file

    implementation 'com.google.firebase:firebase-messaging:21.0.0'
    

    Note: This is the code modification done for the above dependency to resolve deprecation. (Working code as of 1st November 2020)

提交回复
热议问题