Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implement push notification firebase

Tags:

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?

like image 607
stefanosn Avatar asked Oct 21 '20 02:10

stefanosn


People also ask

Can Firebase do push notifications?

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.


1 Answers

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.

like image 189
Doug Stevenson Avatar answered Oct 12 '22 12:10

Doug Stevenson