【问题标题】:Verification failed(Firebase android)验证失败(Firebase android)
【发布时间】:2020-10-16 06:27:33
【问题描述】:

我正在尝试通过 Firebase 制作一个用于电话号码身份验证的应用。但是我一直收到消息验证失败。 这是OTP认证的代码:-

    private void sendVerificationCode(){
        String phoneN =phone.getText().toString();
        
        PhoneAuthProvider.getInstance().verifyPhoneNumber(
                phoneN,                           60,                 
                TimeUnit.SECONDS,   
                Registration.this,               
                mCallbacks);        

    }

    PhoneAuthProvider.OnVerificationStateChangedCallbacks mCallbacks= new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
        @Override
        public void onVerificationCompleted(PhoneAuthCredential phoneAuthCredential) {
            Toast.makeText(Registration.this,"verification completed",Toast.LENGTH_SHORT).show();
            signInWithPhoneAuthCredential(phoneAuthCredential);
        }

        @Override
        public void onVerificationFailed(FirebaseException e) {
            Toast.makeText(Registration.this,"verification failed",Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onCodeSent(String s, PhoneAuthProvider.ForceResendingToken forceResendingToken) {
            //super.onCodeSent(s, forceResendingToken);
            codeSent=s;
        }
    };
    private void VerifyCode(){
        String code= otp.getText().toString();
        PhoneAuthCredential credential = PhoneAuthProvider.getCredential(codeSent, code);
        signInWithPhoneAuthCredential(credential);
    }
    private void signInWithPhoneAuthCredential(PhoneAuthCredential credential) {
        mAuth.signInWithCredential(credential)
                .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {
                        if (task.isSuccessful()) {
                            Toast.makeText(getApplicationContext(),"Welcome, You can login now", Toast.LENGTH_LONG).show();
                            Intent intent = new Intent(Registration.this,Login_Reg.class);
                            startActivity(intent);

                        } else {
                            if (task.getException() instanceof FirebaseAuthInvalidCredentialsException) {
                                // The verification code entered was invalid
                                Toast.makeText(getApplicationContext(),"Incorrect Verification Code",Toast.LENGTH_LONG).show();
                            }

                        }
                    }
                });
    }
}

我不断收到“验证失败”的消息。 下面是用户界面。

如何解决?

【问题讨论】:

标签: java android firebase firebase-authentication


【解决方案1】:

找到解决方案...尝试在实际设备上运行它。它会起作用的。

【讨论】:

    猜你喜欢
    • 2019-03-09
    • 2017-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-09
    • 2017-07-25
    相关资源
    最近更新 更多