I don’t know why I doing wrong, I get this error
"Type mismatch: inferred type is View! but String was expected"
the line that give me the Error is about the "otp"
this is the code:
binding!!.otpView.setOnClickListener { otp ->
val credential = PhoneAuthProvider.getCredential(verificationId!!,otp)
auth!!.signInWithCredential(credential).addOnCompleteListener { task ->
if (task.isSuccessful) {
val intent = Intent(this@OTPActivity, SetupProfileActivity::class.java)
startActivity(intent)
finishAffinity()
} else {
Toast.makeText(this@OTPActivity, "Failed", Toast.LENGTH_SHORT).show()
}
}
}
2
Answers
I found my mistake I use the:
but i need to use that:
There are two lines in your code that contain that symbol:
If
PhoneAuthProvivder
is the one from Firebase, then the second parameter togetCredential()
is supposed to be aString
. However,otp
is aView
, as that is howOnClickListener
works. So, instead of passingotp
togetCredential()
, you need to get some value out ofotp
that represents what you are supposed to give togetCredential()
. According to Firebase, that is supposed to be "the 6 digit SMS-code sent to the user". Ifotp
represents some sort of OTP/PIN view, hopefully it has a function to get what the user typed in, and you will need to call that function and pass its value togetCredential()
.