Hope all of you aware of this class, used to get notification token whenever firebase notification token got refreshed we get the refreshed token from this class, From follo
Kotlin allows for even simpler code than what's shown in other answers.
To get the new token whenever it's refreshed:
class MyFirebaseMessagingService: FirebaseMessagingService() {
override fun onNewToken(token: String?) {
Log.d("FMS_TOKEN", token)
}
...
}
To get the token from anywhere at runtime:
FirebaseInstanceId.getInstance().instanceId.addOnSuccessListener {
Log.d("FMS_TOKEN", it.token)
}
FirebaseinstanceIdService
is deprecated.
So have to use "FirebaseMessagingService"
Sea the image please:
public class MyFirebaseMessagingService extends FirebaseMessagingService {
@Override
public void onNewToken(String s) {
super.onNewToken(s);
Log.e("NEW_TOKEN",s);
}
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
}
}
Just Add This On build.gradle. implementation 'com.google.firebase:firebase-messaging:20.2.3'
You have to use FirebaseMessagingService()
instead of FirebaseInstanceIdService