簡體   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