繁体   English   中英

验证失败(Firebase android)

[英]Verification failed(Firebase android)

我正在尝试通过 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();
                            }

                        }
                    }
                });
    }
}

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

在此处输入图片说明

如何解决这个问题?

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM