I use Firebase auth phone number, the test numbers authenticate successfully, but the real phone number (Vodafone Ukraine operator) does not receive SMS with the code. What can be wrong?

public class LoginActivity extends AppCompatActivity implements View.OnClickListener { private EditText phoneNumberEditText; private EditText verificationCodeEditText; private Button enterCodeButton; private Button getVerificationCodeButton; private FirebaseAuth mAuth; private FirebaseFirestore database; private String codeSent; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); mAuth = FirebaseAuth.getInstance(); database = FirebaseFirestore.getInstance(); bindView(); setListeners(); } private void bindView() { phoneNumberEditText = findViewById(R.id.phone_edit_text); verificationCodeEditText = findViewById(R.id.code_edit_text); enterCodeButton = findViewById(R.id.button_enter_code); getVerificationCodeButton = findViewById(R.id.button_get_code); } private void setListeners() { enterCodeButton.setOnClickListener(this); getVerificationCodeButton.setOnClickListener(this); } @Override public void onClick(View view) { if (view.getId() == R.id.button_enter_code) { String verificationCode = verificationCodeEditText.getText().toString(); verifySignInCode(verificationCode); } else if (view.getId() == R.id.button_get_code) { String phoneNumber = phoneNumberEditText.getText().toString(); sendVerificationCode(phoneNumber); } } private void verifySignInCode(String verificationCode) { PhoneAuthCredential credential = null; try { credential = PhoneAuthProvider.getCredential(codeSent, verificationCode); signInWithPhoneAuthCredential(credential); } catch (IllegalArgumentException e) { verificationCodeEditText.setError("Invalid code"); phoneNumberEditText.requestFocus(); } } private void sendVerificationCode(String phoneNumber) { if (phoneNumber.isEmpty()) { phoneNumberEditText.setError("Phone number is required"); phoneNumberEditText.requestFocus(); return; } if (phoneNumber.length() < 10) { phoneNumberEditText.setError("Please enter a valid phone"); phoneNumberEditText.requestFocus(); return; } PhoneAuthProvider.getInstance().verifyPhoneNumber( phoneNumber, 60, TimeUnit.SECONDS, this, 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()) { final FirebaseUser user = task.getResult().getUser(); updateUI(user); } else { if (task.getException() instanceof FirebaseAuthInvalidCredentialsException) { } } } }); } private void updateUI(FirebaseUser user) { if (user != null) { Intent intent = new Intent(this, MainActivity.class); startActivity(intent); finish(); } } PhoneAuthProvider.OnVerificationStateChangedCallbacks mCallbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() { @Override public void onVerificationCompleted(PhoneAuthCredential phoneAuthCredential) { } @Override public void onVerificationFailed(FirebaseException e) { } @Override public void onCodeSent(String s, PhoneAuthProvider.ForceResendingToken forceResendingToken) { super.onCodeSent(s, forceResendingToken); codeSent = s; } }; 

}

UPDATE: Install the application on the tablet (Android 6.0) entered the phone number on which the code did not come, and the code came on the phone. As a result, I noticed that PhoneAuthProvider.OnVerificationStateChangedCallbacks does not work on the phone (Android 7.0) and therefore IllegalArgumentException throws this method provider PhoneAuthProvider.getCredential(codeSent, verificationCode) because codeSent == null . Why this happens is not clear, on emulators and a tablet there is no such problem.

    1 answer 1

    Solved the problem by simply updating Google services. Sms comes and everything works fine.