skip to Main Content

I’m using firebase messaging in my flutter app but when I run my project it show String token = FirebaseInstanceId.getInstance().getToken(senderId, "*");

when I run my application it shows this error in the console:

C:UserscerbiAppDataLocalPubCachehostedpub.dartlang.orgfirebase_messaging-9.1.4androidsrcmainjavaioflutterpluginsfirebasemessagingFlutterFirebaseMessagingPlugin.java:166: error: cannot find symbol
String token = FirebaseInstanceId.getInstance().getToken(senderId, "*");
^
symbol: variable FirebaseInstanceId
location: class FlutterFirebaseMessagingPlugin
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

What went wrong:
Execution failed for task ‘:firebase_messaging:compileDebugJavaWithJavac’.

and when I navigate to the specific file stated in the error message here is the code in there

        private Task<Map<String, Object>> getToken(Map<String, Object> arguments) {
            return Tasks.call(
                cachedThreadPool,
                () -> {
                  String senderId =
                      arguments.get("senderId") != null
                          ? (String) arguments.get("senderId")
                          : Metadata.getDefaultSenderId(FirebaseApp.getInstance());
                  String token = FirebaseInstanceId.getInstance().getToken(senderId, "*");
                  return new HashMap<String, Object>() {
                    {
                      put("token", token);
                    }
                  };
                });
          }

What can I do to resolve this problem, it seems that the existing code is not working anymore

2

Answers


  1. You should use

    FirebaseMessaging.getInstance().token
    

    to get token, since

    FirebaseInstanceId.getInstance().getToken
    

    is deprecated.

    Login or Signup to reply.
  2. To retrieve the current registration token for an app instance, you need to call
    FirebaseMessaging.instance.getToken(); as stated here in their official guide.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search