I don't know what does this error mean. I've search a lot on Google, but couldn't find why am I getting this error.
E/FirebaseAuth: [SmsRetrieverHelper] SMS verification code request failed: unknown status code: 17006 null
I'm trying to authenticate android client with firebase phone auth sign-in method, and trying to verify their phone number by sending a verification code on their phone. No code is being sent and no callback function is called. I don't know what is the problem here
Here's the activity for getting phone number from edittext, and sending the verification code on that phone number, and starting next activity, where user will enter the code they have got:
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.Log;
import android.widget.Button;
import android.widget.EditText;
import com.google.firebase.FirebaseException;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.PhoneAuthCredential;
import com.google.firebase.auth.PhoneAuthOptions;
import com.google.firebase.auth.PhoneAuthProvider;
import java.util.concurrent.TimeUnit;
public class PhoneOtpAuth extends AppCompatActivity {
private FirebaseAuth mAuth;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_phone_otp_auth);
EditText phoneNumberEditText = findViewById(R.id.phone_number);
Button signIn = findViewById(R.id.sign_in_button);
mAuth = FirebaseAuth.getInstance();
signIn.setOnClickListener(v -> {
String phoneNumber = phoneNumberEditText.getText().toString();
PhoneAuthOptions options =
PhoneAuthOptions.newBuilder(mAuth)
.setPhoneNumber(phoneNumber)
.setTimeout(60L, TimeUnit.SECONDS)
.setActivity(PhoneOtpAuth.this)
.setCallbacks(callbacks)
.build();
PhoneAuthProvider.verifyPhoneNumber(options);
});
}
PhoneAuthProvider.OnVerificationStateChangedCallbacks callbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
@Override
public void onVerificationCompleted(@NonNull PhoneAuthCredential phoneAuthCredential) {
Intent signUpIntent = new Intent(PhoneOtpAuth.this, DriverSignup.class);
startActivity(signUpIntent);
finish();
}
@Override
public void onVerificationFailed(@NonNull FirebaseException e) {
}
@Override
public void onCodeSent(@NonNull String s, @NonNull PhoneAuthProvider.ForceResendingToken forceResendingToken) {
Intent otpVerificationIntent = new Intent(PhoneOtpAuth.this, OtpVerificationActivity.class);
otpVerificationIntent.putExtra("VerificationId", s);
startActivity(otpVerificationIntent);
finish();
}
};
}
Here's the activity for verifying the verification code the user has got from the last (above one) activity:
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.FirebaseException;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.PhoneAuthCredential;
import com.google.firebase.auth.PhoneAuthOptions;
import com.google.firebase.auth.PhoneAuthProvider;
import java.util.concurrent.TimeUnit;
public class OtpVerificationActivity extends AppCompatActivity {
private String otp;
private FirebaseAuth mAuth;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_otp_verification);
EditText otpEditText = findViewById(R.id.otp);
Button verifyOtp = findViewById(R.id.verify_otp_button);
mAuth = FirebaseAuth.getInstance();
otp = otpEditText.getText().toString();
String verificationId = getIntent().getExtras().getString("VerificationId");
FirebaseAuth mAuth = getIntent().getExtras().getParcelable("mAuth");
verifyOtp.setOnClickListener(v -> {
PhoneAuthCredential phoneAuthCredential = PhoneAuthProvider.getCredential(verificationId, otp);
mAuth.signInWithCredential(phoneAuthCredential)
.addOnCompleteListener(task -> {
if(task.isSuccessful()) {
Intent signUpIntent = new Intent(OtpVerificationActivity.this, DriverSignup.class);
startActivity(signUpIntent);
finish();
}
});
});
}
}