Reputation: 193
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();
}
});
});
}
}
Upvotes: 9
Views: 23647
Reputation: 447
Add the number to the test numbers but pay attention That The format of the number should be valid for the used country key
Ex: if we are using US number it should be something like this +1-212-456-7890
if 212 is not a valid open for US numbers it won't work
Upvotes: 0
Reputation: 517
I resolved mine by following these 2 simple steps:
Selecting allow
selected Regions under Authentication like shown in the picture:
By unliking my firebase app from Google Play under Project Settings/Integrations
like below
Upvotes: 2
Reputation: 611
When you repetitively use a specific phone number, signing in and out for the sake of testing, without adding it to "Phone Numbers for Testing", Google might eventually block it temporarily with an error indicating unusual behavior has been detected, or with error: "SMS verification code request failed: unknown status code: 17010 null".
Edit: Please for Accessing the "Phone Numbers for Testing" find the screenshot below:
Upvotes: 10
Reputation: 49
Make sure the device is connected to the internet. Also In the Google Cloud Console, enable the Android DeviceCheck API for your project. That way firebase SDK can verify the device to proceed with authentication.
Upvotes: 4
Reputation: 169
Well I think you might have forgotten to enable the Phone Sign-in method in your firebase console
Try adding phone as Sign-in providers and try again.
Upvotes: 11