I writing a chat app and face with trouble with the OTP Authenticate with Firebase on Android using a Phone Number
whenever I write a real phone number there is a error and it dosent work
and shows me this errors:
Failed to initialize reCAPTCHA config: No Recaptcha Enterprise siteKey configured for tenant/project
[SmsRetrieverHelper] SMS verification code request failed: unknown status code: 17028 Invalid app info in play_integrity_token
here is the code:
String phoneNumber;
Long timeoutSeconds = 30L;
String verificationCode; // for verify the otp
PhoneAuthProvider.ForceResendingToken resendingToken; //for resending the otp to the user
EditText otpInput;
Button nextBtn;
ProgressBar progressBar;
TextView resendOtpTextView;
FirebaseAuth mAuth = FirebaseAuth.getInstance();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login_otp);
otpInput = findViewById(R.id.login_otp);
nextBtn= findViewById(R.id.login_next_btn);
progressBar= findViewById(R.id.login_progressbar);
resendOtpTextView = findViewById(R.id.resend_otp_textview);
// getting the data from another Activity ( phone number --> "LoginOtpActivity")
phoneNumber = getIntent().getExtras().getString("phone");
//starting otp send method with phoneNumber for the first time--> isResend=false
sendOtp(phoneNumber, false); // method
//verifying the OTP code when pressing "NEXT" button
nextBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String enteredOtp = otpInput.getText().toString();
PhoneAuthCredential credential = PhoneAuthProvider.getCredential(verificationCode,enteredOtp);
signIn(credential); // method
setInProgress(true);
}
});
// resending Otp code when pressing "Resend OTP code" textView
resendOtpTextView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
sendOtp(phoneNumber,true); //method
}
});
}
//Send the otp METHOD
void sendOtp (String phoneNumber, boolean isResend){
startResendTimer();//method
setInProgress(true); // set progressBar visible
PhoneAuthOptions.Builder builder =
PhoneAuthOptions.newBuilder(mAuth)
.setPhoneNumber(phoneNumber)
.setTimeout(timeoutSeconds, TimeUnit.SECONDS)
.setActivity(this)
.setCallbacks(new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
@Override
// When otp is automatically entered --> move to username
public void onVerificationCompleted(@NonNull PhoneAuthCredential phoneAuthCredential) {
signIn(phoneAuthCredential);
setInProgress(false);// set progressBar gone
}
@Override
//when something went wrong
public void onVerificationFailed(@NonNull FirebaseException e) {
AndroidUtils.showToast(getApplicationContext(),"OTP verification failed");
setInProgress(false);// set progressBar gone
}
@Override
// this will send the otp to the user
public void onCodeSent(@NonNull String s, @NonNull PhoneAuthProvider.ForceResendingToken forceResendingToken) {
super.onCodeSent(s, forceResendingToken);
verificationCode = s;
resendingToken = forceResendingToken;
AndroidUtils.showToast(getApplicationContext(), "OTP sent successfully");
setInProgress(false);// set progressBar gone
}
});
if (isResend){
//verifying with resendingToken
PhoneAuthProvider.verifyPhoneNumber(builder.setForceResendingToken(resendingToken).build());
}else {
//verify the phone number
PhoneAuthProvider.verifyPhoneNumber(builder.build());
}
}
//set the progressBar/nextBtn to VISIBLE/GONE METHOD
void setInProgress(boolean inProgress){
if (inProgress){
progressBar.setVisibility(View.VISIBLE);
nextBtn.setVisibility(View.GONE);
}else{
progressBar.setVisibility(View.GONE);
nextBtn.setVisibility(View.VISIBLE);
}
}
// login with Firebase and go to next activity METHOD
void signIn(PhoneAuthCredential phoneAuthCredential) {
setInProgress(true);
mAuth.signInWithCredential(phoneAuthCredential).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
setInProgress(false);
Intent intent = new Intent(LoginOtpActivity.this, LoginUsernameActivity.class);
intent.putExtra("phone", phoneNumber);
startActivity(intent);
} else {
AndroidUtils.showToast(getApplicationContext(), "OTP verification failed");
}
}
});
}
// Timer for resending OTP METHOD
void startResendTimer(){
resendOtpTextView.setEnabled(false);
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
timeoutSeconds--;
resendOtpTextView.setText("Resend OTP in " + timeoutSeconds+" seconds");
if (timeoutSeconds<=0){
timeoutSeconds=30L;
timer.cancel();
runOnUiThread(new Runnable() {
@Override
public void run() {
resendOtpTextView.setEnabled(true);
}
});
}
}
},0,1000);
}
tried to check my settings gradle and couldnt fine the problem…