Implement push notification firebase
Asked Answered
S

2

9

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?

Southward answered 21/10, 2020 at 2:17 Comment(0)
Y
8

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.

Yoko answered 21/10, 2020 at 2:31 Comment(2)
Oh i see. So through API i can use the token to send messages to a specific device?Southward
That's what it's for.Yoko
E
0

As mentioned by @doug-stevenson, It is a placeholder. You can copy and add this from firebase-messaging to strings.xml res of your app :

<string name="msg_token_fmt" translatable="false">FCM registration Token: %s</string>
Ellette answered 4/7, 2024 at 6:40 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.