I am trying to make an application that has only a mobile number login facility. I am using Firebase auth, Firestore and Android Studio in Java to make it, I have 5 activities, Home(Splash only)>LoginPhoneNumber>LoginOTP>EnterUsername>MainScreen
the user enters the mobile num with the country code picker in 2nd activity, and OTP is then sent, user enters received OTP in 3rd activity, enters username in 4th act. if otp is verified and is redirected to so called mainscreen.
I have used "+911234567890" as test phone number with otp "111111", and when I test run it with my app, everything works completely fine, all the toasts and code everything.
But when I tried running my app with an actual my own phone number "+919811226XXX", then in the LoginOTP activity I got toast saying, Firebase internal error occured [BILLING_NOT_ENABLED], online I could not find any solutions, some said to activate some premium plan for more sms/day, but in free also i have a limit of 10 sms/day, I haven't used even 1 of it, then why is this error occuring, some said to enable google cloud billing account, but for that I need credit card details and all, which being a kid and student I don't have, neither the money, nor a card or any other verifyable payment option.
Here's my LoginPhoneNumberActivity.java
package com.example.pchat;
public class LoginPhoneNumberActivity extends AppCompatActivity {
CountryCodePicker countryCodePicker;
EditText phoneInput;
Button sendOtpBtn;
ProgressBar progressBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_login_phone_number);
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.phone_login_screen), (v, insets) -> {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets;
});
countryCodePicker = findViewById(R.id.login_countrycode);
phoneInput = findViewById(R.id.login_mobile_number);
sendOtpBtn = findViewById(R.id.send_otp_btn);
progressBar = findViewById(R.id.login_progress_bar);
progressBar.setVisibility(View.GONE);
countryCodePicker.registerCarrierNumberEditText(phoneInput);
sendOtpBtn.setOnClickListener((v)->{
if(!countryCodePicker.isValidFullNumber()){
phoneInput.setError("Phone number not valid");
return;
}
Intent intent = new Intent(LoginPhoneNumberActivity.this,LoginOtpActivity.class);
intent.putExtra("phone",countryCodePicker.getFullNumberWithPlus());
startActivity(intent);
});
}
}
My LoginOtpActivity.java is given below -
package com.example.pchat;
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);
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.login_otp_activity), (v, insets) -> {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets;
});
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 = Objects.requireNonNull(getIntent().getExtras()).getString("phone");
sendOtp(phoneNumber,false);
nextBtn.setOnClickListener(v -> {
String enteredOtp = otpInput.getText().toString();
PhoneAuthCredential credential = PhoneAuthProvider.getCredential(verificationCode,enteredOtp);
signIn(credential);
});
resendOtpTextView.setOnClickListener((v)->{
sendOtp(phoneNumber,true);
});
}
void sendOtp(String phoneNumber,boolean isResend){
startResendTimer();
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) {
AndroidUtil.showToast(getApplicationContext(), "OTP verified successfully!");
signIn(phoneAuthCredential);
setInProgress(false);
}
@Override
public void onVerificationFailed(@NonNull FirebaseException e) {
String Fexceptions = e.getMessage();
AndroidUtil.showToast(getApplicationContext(), Fexceptions);
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
setInProgress(true);
mAuth.signInWithCredential(phoneAuthCredential).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
setInProgress(false);
if(task.isSuccessful()){
Intent intent = new Intent(LoginOtpActivity.this,LoginUsernameActivity.class);
intent.putExtra("phone",phoneNumber);
startActivity(intent);
finish();
}else{
AndroidUtil.showToast(getApplicationContext(),"OTP verification failed");
}
}
});
}
void startResendTimer(){
resendOtpTextView.setEnabled(false);
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@SuppressLint("DefaultLocale")
@Override
public void run() {
timeoutSeconds--;
resendOtpTextView.setText(String.format("Resend OTP after %d seconds", timeoutSeconds));
if(timeoutSeconds<=0){
timeoutSeconds =60L;
timer.cancel();
runOnUiThread(() -> {
resendOtpTextView.setEnabled(true);
});
}
}
},0,1000);
}
}
My LoginUsernameActivity.java Looks somewhat like this below.
package com.example.pchat;
public class LoginUsernameActivity extends AppCompatActivity {
EditText usernameInput;
Button letMeInBtn;
ProgressBar progressBar;
String phoneNumber;
UserModel userModel;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_login_username);
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.login_username_activity), (v, insets) -> {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets;
});
usernameInput = findViewById(R.id.login_username);
letMeInBtn = findViewById(R.id.login_let_me_in_btn);
progressBar =findViewById(R.id.login_progress_bar);
phoneNumber = Objects.requireNonNull(getIntent().getExtras()).getString("phone");
getUsername();
letMeInBtn.setOnClickListener((v -> {
setUsername();
}));
}
void setUsername(){
String username = usernameInput.getText().toString();
if(username.isEmpty() || username.length()<3){
usernameInput.setError("Username length should be at least 3 chars");
return;
}
setInProgress(true);
if(userModel!=null){
userModel.setUsername(username);
}else{
userModel = new UserModel(phoneNumber,username, Timestamp.now(),FirebaseUtil.currentUserId());
}
FirebaseUtil.currentUserDetails().set(userModel).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
setInProgress(false);
if(task.isSuccessful()){
Intent intent = new Intent(LoginUsernameActivity.this,HomeActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK );
startActivity(intent);
finish();
}
}
});
}
void getUsername(){
setInProgress(true);
FirebaseUtil.currentUserDetails().get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
setInProgress(false);
if(task.isSuccessful()){
userModel = task.getResult().toObject(UserModel.class);
if(userModel!=null){
usernameInput.setText(userModel.getUsername());
}
}
}
});
}
void setInProgress(boolean inProgress){
if(inProgress){
progressBar.setVisibility(View.VISIBLE);
letMeInBtn.setVisibility(View.GONE);
}else{
progressBar.setVisibility(View.GONE);
letMeInBtn.setVisibility(View.VISIBLE);
}
}
}
Please help me out
I wanted to make a basic mobile phone login app using firebase auth, It worked perfectly fine with test phone numbers, but showing BILLING NOT ENABLED for a real phone number. What to do, I don't have any money to put on this project. Also, earlier it used to work without any issue, same code, just 1-2 years back, everything used to be the same except this error...
You're getting the BILLING_NOT_ENABLED
error because your Firebase project is on the Spark Plan (No-cost). So it's not about the code you shared but about the changes that were made 2 months ago. So according to this GitHub issue:
All projects utilizing Firebase Phone Authentication (SMS) must be linked to a Cloud Billing account starting from September 1, 2024
This means that you have to explicitly link your project to a Cloud Billing account. However, on the Spark Plan, you should still be able to send 10 free SMS messages per day according to their pricing page.