0

I'm making a simple chat app in android studio, but the phone number OTP failed to sent even though i used a real device to run the app (samsung galaxy a52 android 14).

Here is the code :

package com.daffakhairy.easychat;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.daffakhairy.easychat.utils.AndroidUtil;
import com.google.firebase.Firebase;
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 com.google.firebase.firestore.FirebaseFirestore;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

public class LoginOtpActivity extends AppCompatActivity {

String phoneNumber;
Long timeoutSeconds = 60L;
String verificationCode;
PhoneAuthProvider.ForceResendingToken resendingToken;

EditText otpInput;
Button nextBtn;
ProgressBar progressBar;
TextView resendOtpTextView;
FirebaseAuth mAuth = FirebaseAuth.getInstance();


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    EdgeToEdge.enable(this);
    setContentView(R.layout.activity_login_otp);

    otpInput = findViewById(R.id.login_otp);
    nextBtn = findViewById(R.id.login_next_btn);
    progressBar = findViewById(R.id.login_progress_bar);
    resendOtpTextView = findViewById(R.id.resend_otp_textview);


    phoneNumber = getIntent().getExtras().getString("phone");

    sendOtp(phoneNumber, false);
}

void sendOtp(String phoneNumber,boolean isResend){
    setInProgress(true);
   PhoneAuthOptions.Builder builder =
            PhoneAuthOptions.newBuilder(mAuth)
                    .setPhoneNumber(phoneNumber)
                    .setTimeout(timeoutSeconds, TimeUnit.SECONDS)
                    .setActivity(this)
                    .setCallbacks(new 
PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
                        @Override
                        public void onVerificationCompleted(@NonNull PhoneAuthCredential phoneAuthCredential) {
                            signIn(phoneAuthCredential);
                            setInProgress(false);
                        }

                        @Override
                        public void onVerificationFailed(@NonNull FirebaseException e) {
                            AndroidUtil.showToast(getApplicationContext(),"OTP verification failed");
                            setInProgress(false);
                        }

                        @Override
                        public void onCodeSent(@NonNull String s, @NonNull PhoneAuthProvider.ForceResendingToken forceResendingToken) {
                            super.onCodeSent(s, forceResendingToken);
                            verificationCode = s;
                            resendingToken = forceResendingToken;
                            AndroidUtil.showToast(getApplicationContext(),"OTP sent successfully");
                            setInProgress(false);
                        }
                    });
            if(isResend){
                PhoneAuthProvider.verifyPhoneNumber(builder.setForceResendingToken(resendingToken).build());
            }else{
                PhoneAuthProvider.verifyPhoneNumber(builder.build());
            }
}

void setInProgress(boolean inProgress){
    if(inProgress){
        progressBar.setVisibility(View.VISIBLE);
        nextBtn.setVisibility(View.GONE);
    }else {
        progressBar.setVisibility(View.GONE);
        nextBtn.setVisibility((View.VISIBLE));
    }


}

 void signIn(PhoneAuthCredential phoneAuthCredential){
    //login and go to next activity
}

}

and here is the error in the logcat :

Failed to initialize reCAPTCHA config: No Recaptcha Enterprise siteKey configured for tenant/project *
[SmsRetrieverHelper] SMS verification code request failed: unknown status code: 17499 BILLING_NOT_ENABLED

i have not excel the 10 limit yet, added the sha 1 key, and added all the dependencies needed

1 Answer 1

0

Enable Billing in Firebase

Go to the Firebase Console
Select your project.

In the left sidebar, click on Project Settings (the gear icon).

Under Billing, you will see the option to enable billing for your Firebase project.

If you haven't already, you need to link a billing account to your project.
    If you don't have a billing account, you'll be prompted to create one in Google Cloud.

Important Notes:
    You don’t need to exceed free-tier usage to enable billing; however, enabling billing is required to use SMS verification services.
    After enabling billing, Firebase will give you a $300 free usage credit for 90 days.

Check Firebase Pricing for SMS Verification

Firebase offers a free quota for SMS verifications (the free tier), but once that quota is exhausted, you will need to enable billing to continue using SMS.
You can review the pricing for Firebase Authentication’s phone number sign-in service here.

Verify Billing Setup

After enabling billing, go to your Google Cloud Console and verify that billing is enabled for your project. This ensures that Firebase can use the SMS service without encountering issues like BILLING_NOT_ENABLED.

New contributor
Raj Domadia is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
1
  • i enabled billing and still otp failed to send this doesn't work
    – Kahiry363
    Commented yesterday

Not the answer you're looking for? Browse other questions tagged or ask your own question.