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
You should use
to get token, since
is deprecated.
To retrieve the current registration token for an app instance, you need to call
FirebaseMessaging.instance.getToken();
as stated here in their official guide.