Это мой метод отправки кода:
Код: Выделить всё
public void send_code(){
mCallbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
@Override
public void onCodeSent(@NonNull String s, @NonNull PhoneAuthProvider.ForceResendingToken forceResendingToken) {
super.onCodeSent(s, forceResendingToken);
Log.d("code", "onCodeSent:" + s);
verificationID=s;
}
@Override
public void onVerificationCompleted(@NonNull PhoneAuthCredential phoneAuthCredential) {
}
@Override
public void onVerificationFailed(@NonNull FirebaseException e) {
Toast.makeText(PhoneAuthentication.this, e.getMessage(), Toast.LENGTH_SHORT);
}
};
mPhoneAuthProvider.verifyPhoneNumber(
user_contact , 60, TimeUnit.SECONDS, PhoneAuthentication.this, mCallbacks
);}
Код: Выделить всё
public void verifySignInCode(String code){
try {
PhoneAuthCredential credential = PhoneAuthProvider.getCredential(verificationID, code);
signInWithPhoneAuthCredential(credential);
}catch (Exception e){
Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
Код: Выделить всё
private void signInWithPhoneAuthCredential(PhoneAuthCredential credential){
mFirebaseAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener() {
@Override
public void onComplete(@NonNull Task task) {
if(task.isSuccessful()){
startActivity(new Intent(PhoneAuthentication.this, UserHome.class));
}
else {
Log.d("error:", task.getException().getMessage());
}
}
});
}
Невозможно создать PhoneAuthCredential без подтверждения,
sessionInfo, временное подтверждение или идентификатор регистрации.
Подробнее здесь: https://stackoverflow.com/questions/595 ... essioninfo
Мобильная версия