I am following this tutorial for cloud messaging subscription, and I am running into an issue. I can't import the right Message class i need. I found that i probably missed a dependency, I found I needed this one:
implementation 'com.google.firebase:firebase-admin:6.9.0'
With this dependency the Message class is no longer a problem, however now some stuff changes in my subscribe function:
private fun subscribe(){
val list = mutableListOf<String>()
list.add("dufD62vvRHuL_xZ9ROHTod:APA91bEJJNVPu3lyVbYCcUJqz-5vihXCCBJhtKAohi28CZNDvwb9HsdYCdICFRCjkNaRggr47igapLYEnlEEzN7Mk1ClZoUVT3VdxB6PVBAAa6u0yylo1NojLTLpUDrC8tMqTsBdlKAe\n")
Firebase.messaging.subscribeToTopic("weather")
.addOnCompleteListener { task ->
var msg :String= "Subscribed successfully"
if (!task.isSuccessful) {
msg = "Subcription failed"
}
Log.d("TAG", msg)
Toast.makeText(baseContext, msg, Toast.LENGTH_SHORT).show()
}
}
Right now the subscribeToTopic also expects a list of tokens and i am unable to add a onCompleteListener.
In addition a function I made previously suddenly gets errors
private fun getToken(){
FirebaseMessaging.getInstance().token.addOnCompleteListener(OnCompleteListener { task ->
if (!task.isSuccessful) {
Log.w("TAG", "Fetching FCM registration token failed", task.exception)
return@OnCompleteListener
}
// Get new FCM registration token
val token = task.result
// Log and toast
val msg = token.toString()
Log.d("TAG", msg)
Toast.makeText(baseContext, msg, Toast.LENGTH_LONG).show()
})
}
It seems like the admin dependency messes with the original code.
Is there someone who can help me with this? It would be appreciated.