What to do with the INSTANCE_ID_EVENT action with Firebase 17.0.1?

前端 未结 2 665
梦谈多话
梦谈多话 2021-01-06 07:18

So now that the FirebaseInstanceIdService service is deprecated I\'m unsure what to replace it with.

I previously had a service declared in the manifest like so:

2条回答
  •  南方客
    南方客 (楼主)
    2021-01-06 07:40

    All you need in the manifest is this (note that the service doesn't need android:stopWithTask="false" since it defaults to false:

    
        
            
        
    
    

    And here's the rest of it in beautifully simple Kotlin...

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

提交回复
热议问题