Home » Android » android – Firebase phone number authorization not working – Stack Overflow

android – Firebase phone number authorization not working – Stack Overflow

Posted by: admin February 20, 2020 Leave a comment

Questions:

I am trying to get phone authorization to work but it never seems to send a code to my phone. I am running the test on an emulator but expecting the code on my physical device. is this possible?

I am getting the following in the logcat:

2020-02-19 22:44:18.848 3166-4598/? W/FirebaseAuth: [PhoneVerificationSession] PhoneVerificationSession constructor
2020-02-19 22:44:18.848 3166-11074/? W/FirebaseAuth: [PhoneNumberAuthPostProcessor] postProcess starts
2020-02-19 22:44:19.630 3166-3166/? W/FirebaseAuth: [PhoneVerificationSession] onFailure
2020-02-19 22:44:19.654 3166-11074/? W/FirebaseAuth: [PhoneNumberAuthPostProcessor] postProcess ends

My code is as per the standard Firebase docs:

callbacks = object : PhoneAuthProvider.OnVerificationStateChangedCallbacks() {

            override fun onVerificationCompleted(p0: PhoneAuthCredential) {

            }


            override fun onVerificationFailed(e: FirebaseException) {

                if(e is FirebaseAuthInvalidCredentialsException){

                    phone_buyer_register.error = "Invalid phone number."

                }else if (e is FirebaseTooManyRequestsException){

                    Log.d("tag", "failure")
                    Toast.makeText(applicationContext,"Quota exceeded",Toast.LENGTH_SHORT).show()

                }
            }

            override fun onCodeSent(verificationId: String, token: PhoneAuthProvider.ForceResendingToken) {

                otp_number_register.visibility = View.VISIBLE
                otp_submit.visibility = View.VISIBLE

                Log.d("Tag", "onCodeSent:$verificationId")

            }

        }

and my verification call is as follows:

 private fun startPhonenumberVerification(phone:String) {

    registerbtn.visibility = View.GONE


    PhoneAuthProvider.getInstance().verifyPhoneNumber(
        phone,60,TimeUnit.SECONDS,this,callbacks)

}

Both callbacks and startPhonenumberVerification() are within a clicklistener. What am I doing wrong? I am trying to do this in stages i.e. at least get the code sending working before I move onto the sign-in process but I cannot find my mistake here.

Answers: