Android App with Firebase [Database Problem] - java

A few days ago I began programming an app in "Android Studio".
I recently found Firebase which I wanted to use as an database. My problem now is no matter how I write my code nothing will be written into the "Realtime Database". Sometime my App crashes completely and sometimes there is an endless loop of loading.
If there is anyone out there who could help to write into my database
The structure should be the Following:
Users:
--UID:
----age:
----email:
----fullname:
Here is my code, maybe someone can find my misstake.
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Patterns;
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 com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.FirebaseDatabase;
public class RegisterUser extends AppCompatActivity implements View.OnClickListener {
private TextView banner, registerUser;
private EditText editTextFullName, editTextAge, editTextEmail, editTextPassword;
private ProgressBar progressBar;
private FirebaseAuth databaseAuth;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register_user);
databaseAuth = FirebaseAuth.getInstance();
banner = (TextView) findViewById(R.id.banner);
banner.setOnClickListener(this);
registerUser = (Button) findViewById(R.id.registerUser);
registerUser.setOnClickListener(this);
editTextFullName = (EditText) findViewById(R.id.fullName);
editTextAge = (EditText) findViewById(R.id.age);
editTextEmail = (EditText) findViewById(R.id.email);
editTextPassword = (EditText) findViewById(R.id.password);
progressBar = (ProgressBar) findViewById(R.id.progressBar);
}
#Override
public void onClick(View view) {
switch (view.getId()){
case R.id.banner:
startActivity(new Intent(this, MainActivity.class));
break;
case R.id.registerUser:
registerUser();
break;
}
}
private void registerUser() {
String email = editTextEmail.getText().toString().trim();
String password = editTextPassword.getText().toString().trim();
String fullName = editTextFullName.getText().toString().trim();
String age = editTextAge.getText().toString().trim();
if (fullName.isEmpty()){
editTextFullName.setError("Bitte ausfüllen.");
editTextFullName.requestFocus();
return;
}
if (age.isEmpty()){
editTextAge.setError("Bitte ausfüllen.");
editTextAge.requestFocus();
return;
}
if (email.isEmpty()){
editTextEmail.setError("Bitte ausfüllen.");
editTextEmail.requestFocus();
return;
}
if (!Patterns.EMAIL_ADDRESS.matcher(email).matches()){
editTextEmail.setError("Bitte eine gültige Email-Adresse angeben.");
editTextEmail.requestFocus();
return;
}
if(password.isEmpty()){
editTextPassword.setError("Bitte ausfüllen.");
editTextPassword.requestFocus();
return;
}
if (password.length() < 6){
editTextPassword.setError("Password muss mindestens aus 6 Zeichen bestehen.");
editTextPassword.requestFocus();
return;
}
progressBar.setVisibility(View.VISIBLE);
databaseAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if (task.isSuccessful()){
User user = new User(fullName, age, email);
FirebaseDatabase.getInstance().getReference("Users")
.child(FirebaseAuth.getInstance().getCurrentUser().getUid())
.setValue(user).addOnCompleteListener(new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task) {
if(task.isSuccessful()){
Toast.makeText(RegisterUser.this, "Registrierung erfolgreich!", Toast.LENGTH_SHORT).show();
progressBar.setVisibility(View.GONE);
} else {
Toast.makeText(RegisterUser.this, "Ein Fehler ist aufgetreten! Versuch es erneut.", Toast.LENGTH_SHORT).show();
progressBar.setVisibility(View.GONE);
}
}
});
} else {
Toast.makeText(RegisterUser.this, "Ein Fehler ist aufgetreten! Versuch es erneut.", Toast.LENGTH_SHORT).show();
progressBar.setVisibility(View.GONE);
}
}
});
}
}```

Related

Password length through Firebase authentication

How do I make an error message on password length? through Firebase Authentication for login. If final EditText mpassword.mpassword.setError("Password Must be Between 8 and 15 Characters.");
return;
I have tried to make an if/else statement out of the password length, but that didn't even seem to work right.
Here is the code I have so far.
package com.debatewithus.ui.login;
import android.content.Intent;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.debatewithus.MainActivity;
import com.debatewithus.R;
import com.debatewithus.User;
import com.debatewithus.UserLocalStore;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import static android.icu.lang.UCharacter.GraphemeClusterBreak.V;
public class LoginActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState, ClassNotFoundException task) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sign_up);
Button login;
Button sign_up;
final EditText mail;
final EditText mpassword;
TextView forgotpassword;
final FirebaseAuth auth;
auth = FirebaseAuth.getInstance();
mail = findViewById(R.id.username);
mpassword = findViewById(R.id.Password);
login = findViewById(R.id.login);
sign_up = findViewById(R.id.signup);
forgotpassword = findViewById(R.id.forgotpassword);
login.setOnClickListener((new View.OnClickListener() {
#Override
public void onClick(View v) {
finish();
}
}));
sign_up.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String email_address = mail.getText().toString().trim();
String password = mpassword.getText().toString().trim();
if (TextUtils.isEmpty(email_address)) {
mail.setError("Email is Required.");
return;
}
if (TextUtils.isEmpty(password)) {
mpassword.setError("Password Required.");
return;
if (!(password.length() < 8 && (password.length() > 15))) {
final EditText mpassword.mpassword.setError("Password Must be Between 8 and 15 Characters.");
return;
}
auth.signInWithEmailAndPassword(email_address, password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if (task.isSuccessful())
startActivity(new Intent(getApplicationContext(), MainActivity.class) {
});
else {
Toast.makeText(LoginActivity.this, "Error!" + task.getException().getMessage(), Toast.LENGTH_SHORT).show();
startActivity(new Intent(getApplicationContext(), MainActivity.class));
}
};
});
};
};
});
};
};
You need a logical OR with || instead of a logical AND with &&:
if (!(password.length() < 8 || (password.length() > 15)))
This will evaluate to true if the password length if less than 8 OR greater than 15.
Replace AND with OR , then remove ! . That should do it.
if ((password.length() < 8 || (password.length() > 15))) {

Firebase User == null all the time

My app uses firebase and it needs to send a verification email to the user after registration before they can login. In my code, the app fails to send the verification email and I found out that the user is always null (while debugging) in line 86/88 of my code. any help would be greaty appreciated.
I've tried retracing my steps back but I couldn't get where i nicked an artery
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import static android.text.TextUtils.isEmpty;
public class LoginActivity extends AppCompatActivity {
private FirebaseAuth.AuthStateListener mAuthListener;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
firebaseAuthSetUp();
//widgets
TextView mSignUp = (TextView) findViewById(R.id.sign_up_txt);
TextView forgotPassword = (TextView) findViewById(R.id.forgot_password_txt);
Button mSignIn = (Button) findViewById(R.id.sign_in_btn);
final EditText mEmailSignIn = (EditText) findViewById(R.id.sign_in_email);
final EditText mPasswordSignIn = (EditText) findViewById(R.id.sign_in_password);
mSignUp.setOnClickListener((new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(LoginActivity.this, SignUpActivity.class);
startActivity(intent);
}
}));
//sign in process
mSignIn.setOnClickListener((new View.OnClickListener() {
#Override
public void onClick(View v) {
if (!isEmpty(mEmailSignIn.getText().toString()) && !isEmpty(mPasswordSignIn.getText().toString())) {
//showProgressBar();
FirebaseAuth.getInstance().signInWithEmailAndPassword(mEmailSignIn.getText().toString(), mPasswordSignIn.getText().toString()).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
//hideProgressBar();
}
}).addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
Toast.makeText(LoginActivity.this, " Authentication Failed!!!", Toast.LENGTH_LONG).show();
//hideProgressBar();
}
});
} else {
Toast.makeText(LoginActivity.this, "Please, Fill All Fields", Toast.LENGTH_LONG).show();
}
}
}));
}
//Setting up Firebase
private void firebaseAuthSetUp() {
mAuthListener = new FirebaseAuth.AuthStateListener() {
#Override
public void onAuthStateChanged(#NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
Log.d("TAG", "CurrentUser: " + user);
if (user != null) {
if(user.isEmailVerified()){
Log.d("TAG", "onAuthStateChanged: signed in: " + user.getEmail());
Toast.makeText(LoginActivity.this, "signed in " + user.getUid(), Toast.LENGTH_LONG).show();
} else{
Toast.makeText(LoginActivity.this, "Please Check Your Email Inbox for Verification Link " + user.getUid(), Toast.LENGTH_LONG).show();
FirebaseAuth.getInstance().signOut();
}
} else {
Toast.makeText(LoginActivity.this, "failed to sign in", Toast.LENGTH_LONG).show();
}
}
};
}
#Override
protected void onStart() {
super.onStart();
FirebaseAuth.getInstance().addAuthStateListener(mAuthListener);
}
#Override
protected void onStop() {
super.onStop();
if (mAuthListener != null) {
FirebaseAuth.getInstance().addAuthStateListener(mAuthListener);
}
}
/*public void showProgressBar(){
mProgressBar.setVisibility(View.VISIBLE);
}
public void hideProgressBar(){
if (mProgressBar.getVisibility() == View.VISIBLE){
mProgressBar.setVisibility(View.INVISIBLE);
}
}*/
}```
Thanks a lot #Praveen and #Alex... figured it out, I made a mistake of signing out the user in the else statement [of the if(user.isEmailVerified()) block in the firebaseAuthSetup() method]. probably wouldn't have gotten it if I didn't retrace from the onComplete()

Code jump to the error statement insist of the creating the account in registration app

I am trying to create a registration Activity in my android application when I compile it runs without and error it seems like there is a logical problem when I run my application instant of creating a new account it jumps to the error code as I have provided my registration activity code in the in method creatnewAccount() in the if statement where I have tried to check whether the rpassword and the password are same. Whenever I run my application and enter the detail and click signup button it jumps to the else statement. Can't understand what's the error and what should I do
package com.nanb.chaton;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import static android.widget.Toast.LENGTH_SHORT;
public class Register extends AppCompatActivity {
private EditText Email, Password, Repassword;
private Button Signup, Login;
private FirebaseAuth mAuth;
private ProgressDialog lodingBar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
mAuth = FirebaseAuth.getInstance();
rimplemantaion();
sendusertoLogin();
createAccount();
}
private void createAccount() {
Signup.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
createnewAccount();
}
});
}
private void createnewAccount() {
String email = Email.getText().toString();
String password = Password.getText().toString();
String rpassword = Repassword.getText().toString();
if (TextUtils.isEmpty(email)){
Toast.makeText(this, "Please enter email i'd ", LENGTH_SHORT).show();
}
if (TextUtils.isEmpty(password)){
Toast.makeText(this, "Please enter Password ", LENGTH_SHORT).show();
}
if (TextUtils.isEmpty(rpassword)){
Toast.makeText(this, "Please enter Re-Password ", LENGTH_SHORT).show();
}
if (rpassword == password ){
lodingBar.setTitle("Creating new account");
lodingBar.setMessage("Pleased wait till we creat your account");
lodingBar.setCanceledOnTouchOutside(true);
lodingBar.show();
mAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
sendusertoLogin();
Toast.makeText(Register.this,"Account created succcessfully", Toast.LENGTH_SHORT).show();
lodingBar.dismiss();
}else{
Toast.makeText(Register.this,"Sorry,There is a problem while creating your accout. Please try again later", LENGTH_SHORT).show();
lodingBar.dismiss();
}
}
});
}
else{
Toast.makeText(this, "Password and Re-enter password are not same ", LENGTH_SHORT).show();
}
}
private void sendusertoLogin() {
Login.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent loginIntent = new Intent(Register.this, Login.class);
startActivity(loginIntent);
}
});
}
private void rimplemantaion() {
Email = (EditText) findViewById(R.id.email);
Password = (EditText) findViewById(R.id.password);
Repassword = (EditText) findViewById(R.id.Rpassword);
Signup = (Button) findViewById(R.id.SignUp);
Login = (Button) findViewById(R.id.LogIn);
lodingBar = new ProgressDialog(this);
}
}
Replace this
if (rpassword == password ){
}
else{
Toast.makeText(this, "Password and Re-enter password are not same ", LENGTH_SHORT).show();
}
with this
if (rpassword.equals(password) ){
}
else{
Toast.makeText(this, "Password and Re-enter password are not same ", LENGTH_SHORT).show();
}

Issue with signing in to an application

I have an issue regarding signing in..!
package com.example.myapplication;
import android.app.ProgressDialog;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import java.util.HashMap;
public class RegisterActivity extends AppCompatActivity
{
private Button CreateAccountButton;
private EditText InputName, InputPhoneNumber, InputPassword;
private ProgressDialog loadingBar;
FirebaseAuth mAuth;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
CreateAccountButton = (Button) findViewById(R.id.main_register_btn);
InputName = (EditText) findViewById(R.id.register_username_input);
InputPassword = (EditText) findViewById(R.id.register_password_input);
InputPhoneNumber = (EditText) findViewById(R.id.register_phone_number_input);
loadingBar = new ProgressDialog(this);
mAuth = FirebaseAuth.getInstance();
CreateAccountButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v)
{
CreateAccount();
}
});
}
private void CreateAccount()
{
String name = InputName.getText().toString();
String phone = InputPhoneNumber.getText().toString();
String password = InputPassword.getText().toString();
if (TextUtils.isEmpty(name))
{
Toast.makeText(this, "please enter your name", Toast.LENGTH_SHORT).show();
}
else if (TextUtils.isEmpty(phone))
{
Toast.makeText(this, "please enter your phone number", Toast.LENGTH_SHORT).show();
}
else if (TextUtils.isEmpty(password))
{
Toast.makeText(this, "please enter your password", Toast.LENGTH_SHORT).show();
}
else
{
loadingBar.setTitle("Create Account");
loadingBar.setMessage("Please wait, While we are checking the credentials");
loadingBar.setCanceledOnTouchOutside(false);
loadingBar.show();
validatephonenumber(name, phone, password);
}
}
private void validatephonenumber(final String name, final String phone, final String password)
{
final DatabaseReference RootRef;
RootRef = FirebaseDatabase.getInstance().getReference();
RootRef.addListenerForSingleValueEvent(new ValueEventListener()
{
#Override
public void onDataChange(#NonNull DataSnapshot dataSnapshot)
{
if(dataSnapshot.child("Users").child(phone).exists())
{ Toast.makeText(RegisterActivity.this, "this" +phone+ "alredy exists", Toast.LENGTH_SHORT).show();
loadingBar.dismiss();
Toast.makeText(RegisterActivity.this, "Please try using another phone number", Toast.LENGTH_SHORT).show();
Intent intent= new Intent(RegisterActivity.this, MainActivity.class);
startActivity(intent);
}
else
{
HashMap<String, Object> userdataMap = new HashMap<>();
userdataMap.put("Phone", phone);
userdataMap.put("password", password);
userdataMap.put("name", name);
RootRef.child("User").child(phone).updateChildren(userdataMap)
.addOnCompleteListener(new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task)
{
if (task.isSuccessful())
{
Toast.makeText(RegisterActivity.this, "Congratulations your account has been created ", Toast.LENGTH_SHORT).show();
loadingBar.dismiss();
Intent intent= new Intent(RegisterActivity.this, loginActivity.class);
startActivity(intent);
}
else
{
loadingBar.dismiss();
Toast.makeText(RegisterActivity.this, "Network Error: Please try again", Toast.LENGTH_SHORT).show();
}
}
});
}
}
#Override
public void onCancelled(#NonNull DatabaseError databaseError) {
}
});
}
}
when I'm using this code and signing in with a phone number for the second it should actually prompt "this number already exists" but it isn't working and upon signing in with the same number again all the older names and passwords are being replaced by new ones....how can I solve this issue???
try to remove your intent flow ;-
Intent intent= new Intent(RegisterActivity.this, MainActivity.class);
startActivity(intent);

Firebase Email and password Authentication fails mAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener((task)

This is my CustomerLoginRegisterActivity.java that gets customer's Email and password for login and registers email and password to firebase if they don't have an account,
i refered this tutorial : https://youtu.be/d8JMjBMQaMk?list=PLxefhmF0pcPl6gcWvrpTbjGO7rcMWY1jT
But The Firebase authentication fails everytime during registration.
I've enabled Sign-In method in my Firebase Account
package com.example.saiadarsh.appendly;
import android.app.ProgressDialog;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.gms.common.SignInButton;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
public class CustomerLoginRegisterActivity extends AppCompatActivity {
private Button CustomerLoginButton;
private Button CustomerRegisterButton;
private TextView CustomerRegisterLink;
private TextView CustomerStatus;
private EditText EmailCustomer;
private EditText PasswordCustomer;
private ProgressDialog loadingBar;
private FirebaseAuth mAuth;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_customer_login_register);
mAuth = FirebaseAuth.getInstance();
CustomerLoginButton = (Button) findViewById(R.id.customer_login_btn);
CustomerRegisterButton = (Button) findViewById(R.id.customer_register_btn);
CustomerRegisterLink = (TextView) findViewById(R.id.register_customer_link);
CustomerStatus = (TextView) findViewById(R.id.customer_status);
EmailCustomer = (EditText) findViewById(R.id.email_customer);
PasswordCustomer = (EditText) findViewById(R.id.password_customer);
loadingBar = new ProgressDialog(this);
CustomerRegisterButton.setVisibility(View.INVISIBLE);
CustomerRegisterButton.setEnabled(false);
CustomerRegisterLink.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
CustomerLoginButton.setVisibility(View.INVISIBLE);
CustomerRegisterLink.setVisibility(View.INVISIBLE);
CustomerStatus.setText("Register Customer");
CustomerRegisterButton.setVisibility(View.VISIBLE);
CustomerRegisterButton.setEnabled(true);
}
});
CustomerRegisterButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view)
{
String email = EmailCustomer.getText().toString();
String password = PasswordCustomer.getText().toString();
RegisterCustomer(email, password);
}
});
CustomerLoginButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String email = EmailCustomer.getText().toString();
String password = PasswordCustomer.getText().toString();
SignInCustomer(email, password);
}
});
}
private void SignInCustomer(String email, String password)
{
if(TextUtils.isEmpty(email))
{
Toast.makeText(CustomerLoginRegisterActivity.this, "Please write Email...", Toast.LENGTH_SHORT).show();
}
if(TextUtils.isEmpty(password))
{
Toast.makeText(CustomerLoginRegisterActivity.this, "Please write Password...", Toast.LENGTH_SHORT).show();
}
else
{
loadingBar.setTitle("Customer Login");
loadingBar.setMessage("Please wait, while we are on it");
loadingBar.show();
mAuth.signInWithEmailAndPassword(email, password)
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task)
{
if(task.isSuccessful())
{
Toast.makeText(CustomerLoginRegisterActivity.this, "Customer Login Successfully", Toast.LENGTH_SHORT).show();
loadingBar.dismiss();
}
else
{
Toast.makeText(CustomerLoginRegisterActivity.this, "Login Unsuccessful, Please Try Again.....", Toast.LENGTH_SHORT).show();
loadingBar.dismiss();
}
}
});
}
}
private void RegisterCustomer(String email, String password)
{
if(TextUtils.isEmpty(email))
{
Toast.makeText(CustomerLoginRegisterActivity.this, "Please write Email...", Toast.LENGTH_SHORT).show();
}
if(TextUtils.isEmpty(password))
{
Toast.makeText(CustomerLoginRegisterActivity.this, "Please write Password...", Toast.LENGTH_SHORT).show();
}
else
{
loadingBar.setTitle("Customer Registration");
loadingBar.setMessage("Please wait, while we are on it");
loadingBar.show();
mAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task)
{
if(task.isSuccessful())
{
Toast.makeText(CustomerLoginRegisterActivity.this, "Customer Registered Successfully", Toast.LENGTH_SHORT).show();
loadingBar.dismiss();
}
else
{
Toast.makeText(CustomerLoginRegisterActivity.this, "Registeration Unsuccessful, Please Try Again.....", Toast.LENGTH_SHORT).show();
loadingBar.dismiss();
}
}
});
}
}
}

Categories

Resources