I am using the code from this page to get the token https://firebase.google.com/docs/cloud-messaging/android/client but i am getting an error on this specific line String msg = getString(R.string.msg_token_fmt, token);
for msg_token_fmt saying can not resolve symbol. I have done all steps in this tutorial but i get this error.
This is the code
FirebaseMessaging.getInstance().getToken()
.addOnCompleteListener(new OnCompleteListener<String>() {
@Override
public void onComplete(@NonNull Task<String> task) {
if (!task.isSuccessful()) {
Log.w(TAG, "Fetching FCM registration token failed", task.getException());
return;
}
// Get new FCM registration token
String token = task.getResult();
// Log and toast
String msg = getString(R.string.msg_token_fmt, token);
Log.d(TAG, msg);
Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show();
}
});
What am i missing?
Firebase Cloud Messaging (FCM) provides a reliable and battery-efficient connection between your server and devices that allows you to deliver and receive messages and notifications on iOS, Android, and the web at no cost.
That code is just provided as an example. If you don't intend to format the token
string with a string resource from your app, then you don't need that line of code at all. Just do whatever you want with token
after you receive it. Typically you send it to your backend so that the token can be used to target this device with messages using the FCM send API.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With