我目前正在制作一个android应用,需要验证用户是否使用OTP输入了正确的手机号码。 用户已经使用他的电子邮件和密码登录了应用程序。 现在,我需要验证用户输入的手机号码,而不使用firebase电话auth的signInWithCrendntial()方法。 我该怎么办?
我的mCallbacks是
@Override
public void onVerificationCompleted(PhoneAuthCredential credential) {
Toast.makeText(getApplicationContext(), "Verification Complete", Toast.LENGTH_SHORT).show();
showMessage("Success!!","OTP verified!" + credential);
cred = credential;
//btn_add_guest.setEnabled(true);
}
@Override
public void onVerificationFailed(FirebaseException e) {
Toast.makeText(getApplicationContext(), "Verification Failed", Toast.LENGTH_SHORT).show();
Log.i(TAG,"Error is "+e.getMessage());
}
@Override
public void onCodeSent(String verificationId,
PhoneAuthProvider.ForceResendingToken token) {
Toast.makeText(getApplicationContext(), "Code Sent", Toast.LENGTH_SHORT).show();
mVerificationId = verificationId;
mResendToken = token;
Log.i(TAG,"VERFICATION ID IS"+mVerificationId);
Log.i(TAG,"RESEND TOKEN"+mResendToken);
btn_add_guest.setEnabled(false);
}
};
我要在按钮上调用此方法。Pressd其中put_otp是textView,用户在其中输入OTP。
verifyPhoneNumberWithCode(mVerificationId,put_otp.getText().toString());
PhoneAuthCredential credential = PhoneAuthProvider.getCredential(mVerificationId, put_otp.getText().toString());
Log.i(TAG,credential.getProvider());
private void verifyPhoneNumberWithCode(String verificationId, String code) {
Log.i(TAG,"RESEND TOKEN IN METHOD IS"+mResendToken); if(code.equals(mResendToken)&&verificationId.equals(mVerificationId)){
Toast.makeText(AddGuestActivity.this, "Verification Success", Toast.LENGTH_SHORT).show();
btn_add_guest.setEnabled(true);
}
else
Toast.makeText(this,"Please provide correct OTP",Toast.LENGTH_SHORT).show();
}
答案 0 :(得分:0)
您可以将电子邮件/密码帐户与电话帐户https://firebase.google.com/docs/auth/android/account-linking?authuser=0
关联