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:
- Add internet permission in manifest:
- Download google.json file from firebase after entering sha1 and sha256
- Enable android device verification in google cloud.
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?