I have created a normal Sign Up page in Android Studio and I have linked this to Firebase. The language used is java.
"Signup.java"
package com.example.test;
import androidx.appcompat.app.AppCompatActivity;
import android.app.Activity;
import android.app.ActivityOptions;
import android.content.Intent;
import android.os.Bundle;
import android.os.StrictMode;
import android.util.Pair;
import android.util.Patterns;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.google.android.material.textfield.TextInputLayout;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
public class Signup extends AppCompatActivity {
TextInputLayout regName, regEmail, regPhoneNo, regPassword, regConfirmPassword;
Button regSignInBtn, regToLoginBtn;
FirebaseDatabase rootNode;
DatabaseReference reference;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_signup);
regName = findViewById(R.id.reg_name_txt);
regEmail = findViewById(R.id.reg_mail_txt);
regPhoneNo = findViewById(R.id.reg_phone_no_txt);
regPassword = findViewById(R.id.reg_password_txt);
regConfirmPassword = findViewById(R.id.reg_confirm_password);
regSignInBtn = findViewById(R.id.reg_signin_btn);
regToLoginBtn = findViewById(R.id.reg_login_btn);
regSignInBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
rootNode = FirebaseDatabase.getInstance();
reference = rootNode.getReference("Users");
String name = regName.getEditText().getText().toString();
String email = regEmail.getEditText().getText().toString();
String phoneNo = regPhoneNo.getEditText().getText().toString();
String password = regPassword.getEditText().getText().toString();
String confirmPassword = regConfirmPassword.getEditText().getText().toString();
if (!name.isEmpty() && !email.isEmpty() && !phoneNo.isEmpty() && !password.isEmpty() && !confirmPassword.isEmpty()) {
/*&& phoneNo.length() == 10 && password == confirmPassword && Patterns.EMAIL_ADDRESS.matcher(email).matches()*/
UserHelperClass helperClass = new UserHelperClass(name, email, phoneNo, password, confirmPassword);
reference.setValue(helperClass);
Toast.makeText(Signup.this, "User Created!!! Kindly Login!", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(Signup.this,"Kindly Check All the Values!!!",Toast.LENGTH_LONG).show();
}
}
});
}
}
I have created a separate class to get the values and the code is below:
"Helperclass.java"
package com.example.test;
public class UserHelperClass {
String name, email, phoneNumber, password, confirmPassword;
public UserHelperClass() {
// Empty Constructor for DB
}
public UserHelperClass(String name, String email, String phoneNumber, String password, String confirmPassword) {
this.name = name;
this.email = email;
this.phoneNumber = phoneNumber;
this.password = password;
this.confirmPassword = confirmPassword;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getConfirmPassword() {
return confirmPassword;
}
public void setConfirmPassword(String confirmPassword) {
this.confirmPassword = confirmPassword;
}
}
Now when I click the Sign In button I see there is no errors and the code is able to get into the If-Else Loop created in the "Signup.java" file.
But then comes the issue. The user details are not getting into the Firebase I am using.
I have even checked the rules and I have added the dependencies.
Android Studio Dependencies:
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.6.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'com.google.android.material:material:1.6.0'
implementation 'com.google.firebase:firebase-database:20.0.5'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation platform('com.google.firebase:firebase-bom:30.1.0')
implementation 'com.google.firebase:firebase-database'
Firebase Rules:
{
"rules": {
".read": true,
".write": true,
}
}
Sign Up confirmation from Android Studio when it enters If loop
No Data getting sent into Firebase