【发布时间】:2017-12-31 15:31:50
【问题描述】:
这是我用于 firebase 登录的代码。完成验证后,我将退出。但是当我尝试使用相同的号码再次登录时,它不会向我发送 otp。
帮助我退出它。 提前致谢。 这是代码:
@Override
public void onVerificationCompleted(PhoneAuthCredential credential) {
// This callback will be invoked in two situations:
// 1 - Instant verification. In some cases the phone number can be instantly
// verified without needing to send or enter a verification code.
// 2 - Auto-retrieval. On some devices Google Play services can automatically
// detect the incoming verification SMS and perform verificaiton without
// user action.
// Log.d(TAG, "onVerificationCompleted:" + credential);
//mAuth.signOut();
mAuth= FirebaseAuth.getInstance();
if(mAuth!=null)
mAuth.signOut();
Toast.makeText(MainActivity.this,"verification complete",Toast.LENGTH_SHORT).show();
}
@Override
public void onCodeSent(String verificationId,
PhoneAuthProvider.ForceResendingToken token) {
// The SMS verification code has been sent to the provided phone number, we
// now need to ask the user to enter the code and then construct a credential
// by combining the code with a verification ID.
// Log.d(TAG, "onCodeSent:" + verificationId);
Toast.makeText(MainActivity.this,"code sent",Toast.LENGTH_SHORT).show();
// Save verification ID and resending token so we can use them later
mVerificationId = verificationId;
mResendToken = token;
mobileNumber.setVisibility(View.GONE);
submit.setVisibility(View.GONE);
otpButton.setVisibility(View.VISIBLE);
otpText.setVisibility(View.VISIBLE);
t1.setVisibility(View.GONE);
t2.setVisibility(View.VISIBLE);
mAuth= FirebaseAuth.getInstance();
}
otpButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PhoneAuthCredential credential = PhoneAuthProvider.getCredential(mVerificationId,otpText.getText().toString());
signInWithPhoneAuthCredential(credential);
}
});
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PhoneAuthProvider.getInstance().verifyPhoneNumber(
"+91"+mobileNumber.getText().toString(),// Phone number to verify
60,// Timeout duration
TimeUnit.SECONDS,// Unit of timeout
MainActivity.this,// Activity (for callback binding)
mCallbacks);
}
});
}
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(MainActivity.this,"verification
done",Toast.LENGTH_SHORT).show();
FirebaseUser user = task.getResult().getUser();
} else {
if (task.getException() instanceof
FirebaseAuthInvalidCredentialsException) {
Toast.makeText(MainActivity.this,"verification failed code
invalid",Toast.LENGTH_SHORT).show();
}
}
}
});
}
【问题讨论】:
-
otp ?那是什么意思?
-
发布您的登录代码,因为对我来说您的注销很好,但您再次登录时遇到问题,谢谢:)
-
其实这个方法是在验证移动OTP代码时运行的。
-
等待我上传。
-
(第一个代码块后面跟着一个悬空的“}”:修正缩进。)
标签: android firebase firebase-authentication one-time-password