FirebaseInstanceIdService is deprecated

后端 未结 10 2347

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)
    }
    

提交回复
热议问题