skip to Main Content

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


  1. Chosen as BEST ANSWER

    I found my mistake I use the:

    binding!!.otpView.setOnClickListener { otp ->
    

    but i need to use that:

     binding!!.otpView.setOtpCompletionListener { otp ->
    

  2. the line that give me the Error is about the "otp"

    There are two lines in your code that contain that symbol:

          binding!!.otpView.setOnClickListener { otp ->
            val credential = PhoneAuthProvider.getCredential(verificationId!!,otp)
    

    If PhoneAuthProvivder is the one from Firebase, then the second parameter to getCredential() is supposed to be a String. However, otp is a View, as that is how OnClickListener works. So, instead of passing otp to getCredential(), you need to get some value out of otp that represents what you are supposed to give to getCredential(). According to Firebase, that is supposed to be "the 6 digit SMS-code sent to the user". If otp 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 to getCredential().

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search