Reputation: 161
I am trying to get fcm token and store it in cloud firestore:
val user = User(et_email_sign_up_activity.text.toString(), et_name_sign_up_activity.text.toString(),
et_mobile_sign_up_activity.text.toString(), "",
FirebaseAuth.getInstance().currentUser?.uid!!, tv_address.text!!.toString(), getToken())
Firebase().uploadUserSignIn(user, this)//uploads user to cloud firestore
getToken():
private fun getToken(): String{
var token = ""
FirebaseMessaging.getInstance().token.addOnSuccessListener {
token = it
Log.i("token", it)
}.addOnFailureListener {
val dialog = AlertDialog.Builder(this)
dialog.setMessage(it.toString())
dialog.show()
}
return token
}
I always get this error whenever I try to execute my code in real android device:
E/FirebaseMessaging: Topic sync or token retrieval failed on hard
failure exceptions: java.util.concurrent.ExecutionException:
java.io.IOException: SERVICE_NOT_AVAILABLE. Won't retry the operation.
I have google play services running with proper internet connection
Few solutions I have tried:
Sometimes I don't get the error and fcm token is returned successfully returned but most of the times I get this error.
What is the error?
Upvotes: 11
Views: 19857
Reputation: 16086
Even I am facing same problem, this issue comes when your device is not able to communicate with FCM due to some reason. You can perform following checks to make it working:
Upvotes: 15