FirebaseInstanceIdService is deprecated

后端 未结 10 2178

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

相关标签:
10条回答
  • 2020-11-22 10:39

    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)
    }
    
    0 讨论(0)
  • 2020-11-22 10:40

    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);
        }
    }
    
    0 讨论(0)
  • 2020-11-22 10:41

    Just Add This On build.gradle. implementation 'com.google.firebase:firebase-messaging:20.2.3'

    0 讨论(0)
  • 2020-11-22 10:43

    You have to use FirebaseMessagingService() instead of FirebaseInstanceIdService

    0 讨论(0)
提交回复
热议问题