Everything looks fine to me, I just want to register a user in firebase but it doesn't work. Here is my activity:
public class SignUp extends Activity {
Button signup1;
EditText email1, password1, password2;
FirebaseAuth firebaseAuth;
ProgressDialog progressDialog;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sign_up);
//Instantiate the FirebaseAuth object
firebaseAuth = FirebaseAuth.getInstance();
signup1 = (Button) findViewById(R.id.signup);
// Setting the listener for button
signup1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
register();
}
});
email1 = (EditText) findViewById(R.id.email);
password1 = (EditText) findViewById(R.id.password1);
password2 = (EditText) findViewById(R.id.password2);
progressDialog = new ProgressDialog(this);
}
public void register() {
String email = email1.getText().toString().trim();
String pass1 = password1.getText().toString().trim();
String pass2 = password2.getText().toString().trim();
if (TextUtils.isEmpty(email)) {
Toast.makeText(this, "Please Enter an Email", Toast.LENGTH_SHORT).show();
return;
}
if (TextUtils.isEmpty(pass1)) {
Toast.makeText(this, "Please Enter Password", Toast.LENGTH_SHORT).show();
return;
}
if (TextUtils.isEmpty(pass2)) {
Toast.makeText(this, "Please Enter Password Again", Toast.LENGTH_SHORT).show();
return;
}
if (TextUtils.equals(pass1, pass2)) {
progressDialog.setMessage("Registering....!");
progressDialog.show();
firebaseAuth.createUserWithEmailAndPassword(email, pass2).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Toast.makeText(SignUp.this,"SignUp Successfully", Toast.LENGTH_SHORT).show();
}
else {
Toast.makeText(SignUp.this, "SignUp Failed... Try Again", Toast.LENGTH_SHORT).show();
}
progressDialog.dismiss();
}
});
}
else {
Toast.makeText(this, "Password does not Match", Toast.LENGTH_SHORT).show();
return;
}
}
}
The application stucks when it goes into "createUserWithEmailAndPassword".
Use try-catch for exception.
For example createUser... method is null and catch it and resolve.
Related
I am new to android so there is some problem when i run the code to register or login with firebase authentication i can run the code but when i execute the signup function after pressing the register button it takes a lot time to register 1 account.
`
public class RegisterActivity extends AppCompatActivity implements View.OnClickListener {
private FirebaseAuth mAuth;
private Button btn_register;
private EditText et_name, et_age, et_email, et_password;
private ProgressBar ProgressBar;
private TextView name_project;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
mAuth = FirebaseAuth.getInstance();
name_project = (TextView) findViewById(R.id.name_project);
name_project.setOnClickListener(this);
btn_register = (Button) findViewById(R.id.btn_register);
btn_register.setOnClickListener(this);
et_name = (EditText) findViewById(R.id.et_name);
et_age = (EditText) findViewById(R.id.et_age);
et_email = (EditText) findViewById(R.id.et_email);
et_password = (EditText) findViewById(R.id.et_password);
ProgressBar = (ProgressBar) findViewById(R.id.progressBar);
}
#Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.name_project:
startActivity(new Intent(this, MainActivity.class));
break;
case R.id.btn_register:
registerUser();
break;
}
}
private void registerUser() {
String email = et_email.getText().toString().trim();
String password = et_password.getText().toString().trim();
String name = et_name.getText().toString().trim();
String age = et_age.getText().toString().trim();
if (name.isEmpty()) {
et_name.setError("Please enter your full name");
et_name.requestFocus();
return;
}
if (age.isEmpty()) {
et_age.setError("Please enter your age");
et_age.requestFocus();
return;
}
if (email.isEmpty()) {
et_email.setError("Please enter your email");
et_email.requestFocus();
return;
}
if (password.isEmpty()) {
et_password.setError("Please enter your password");
et_password.requestFocus();
return;
}
if (!Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
et_email.setError("Please enter valid email");
et_email.requestFocus();
return;
}
if (password.length() < 6) {
et_password.setError("The length of password should be more than 6 letters");
et_password.requestFocus();
return;
}
ProgressBar.setVisibility(View.VISIBLE);
mAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Intent intent = new Intent(RegisterActivity.this, MainActivity.class);
startActivity(intent);
finish();
Toast.makeText(RegisterActivity.this, "Registered successfully", Toast.LENGTH_SHORT).show();
ProgressBar.setVisibility(View.GONE);
} else {
Toast.makeText(RegisterActivity.this, "Registered fail", Toast.LENGTH_SHORT).show();
ProgressBar.setVisibility(View.GONE);
}
}
});
}
}
enter image description here`
I have tried many methods but registration takes a long time.
Please make sure you have enabled the Email/Password provider in the Authentification tab on the Firebase console.
I have been able to get the email sent and verified but fire base isn't updating. Also when I check to reset the password the email is sent reset and fire base isn't changing that either. How can I change it to where the password and the email verification will update in fire base?
I have searched several sites and looked at several videos. I am really new to coding. Thanks for the help.
this is my login:
public class Login extends AppCompatActivity implements View.OnClickListener {
//Variables
private Button register, signin, forgotpassword;
private TextInputLayout Email, Password;
private FirebaseAuth mAuth;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_login);
register = findViewById(R.id.register);
register.setOnClickListener(this);
signin = (Button)findViewById(R.id.SignIn);
signin.setOnClickListener( this );
Email = findViewById( R.id.email );
Password = findViewById( R.id.password );
mAuth = FirebaseAuth.getInstance();
forgotpassword = (Button) findViewById(R.id.forgot_password);
forgotpassword.setOnClickListener(this);
}
#Override
public void onClick(View v) {
switch (v.getId()){
case R.id.register:
startActivity(new Intent(this, SignUp.class));
break;
case R.id.SignIn:
startActivity( new Intent(this,UserInterface.class) );
break;
case R.id.forgot_password:
startActivity( new Intent(this,ForgotPass.class) );
break;
}
}
private void userlogin() {
String email = Email.getEditText().getText().toString().trim();
String password = Password.getEditText().getText().toString().trim();
if (email.isEmpty()){
Email.setError("Email is required!");
Email.requestFocus();
return;
}
if (!Patterns.EMAIL_ADDRESS.matcher(email).matches()){
Email.setError("Please provide valid Email!");
Email.requestFocus();
return;
}
if (password.isEmpty()){
Password.setError("Password is required!");
Password.requestFocus();
return;
}
if (password.length() < 6){
Password.setError("Min password length is 6 characters!");
Password.requestFocus();
return;
}
mAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener( new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if (task.isSuccessful()){
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if (user.isEmailVerified()){
startActivity(new Intent(Login.this, UserInterface.class));
}else{
user.sendEmailVerification();
Toast.makeText(Login.this, "Check your email to verify your account!", Toast.LENGTH_LONG).show();
}
}else {
Toast.makeText(Login.this, "Failed to login! Please check Email and Password", Toast.LENGTH_LONG).show();
}
}
});
}
}
This is my forgot password
public class ForgotPass extends AppCompatActivity {
private Button reset_password;
private TextInputLayout fullname, email;
FirebaseAuth auth;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate( savedInstanceState );
getWindow().setFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView( R.layout.activity_forgot_pass );
email = findViewById(R.id.email);
fullname = findViewById(R.id.fullname);
reset_password = (Button) findViewById(R.id.fp_submit);
auth = FirebaseAuth.getInstance();
reset_password.setOnClickListener( new View.OnClickListener() {
#Override
public void onClick(View v) {
fp_submit();
}
} );
}
private void fp_submit(){
String email = this.email.getEditText().getText().toString().trim();
String fullname = this.fullname.getEditText().getText().toString().trim();
if (fullname.isEmpty()){
this.fullname.setError( "Name is required" );
this.fullname.requestFocus();
return;
}
if (email.isEmpty()){
this.email.setError( "Email is required" );
this.email.requestFocus();
return;
}
if (!Patterns.EMAIL_ADDRESS.matcher( email ).matches()){
this.email.setError( "Please priovide valid email" );
this.email.requestFocus();
return;
}
//progressBar.setVisibility(View.VISIBLE)
auth.sendPasswordResetEmail( email ).addOnCompleteListener( new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task) {
if (task.isSuccessful()){
Toast.makeText( ForgotPass.this, "Check your email to reset your password",Toast.LENGTH_LONG ).show();
startActivity( new Intent(ForgotPass.this, Login.class) );
}else{
Toast.makeText( ForgotPass.this, "Please try again!", Toast.LENGTH_LONG ).show();
}
}
} );
}
}
This is my sign up
public class SignUp extends AppCompatActivity implements View.OnClickListener {
private FirebaseAuth mAuth;
private TextInputLayout FullName, UserName, Email, Password;
private Button Submit, login;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_sign_up);
mAuth = FirebaseAuth.getInstance();
login = (Button)findViewById(R.id.login);
login.setOnClickListener(this);
Submit = (Button) findViewById(R.id.submit);
Submit.setOnClickListener(this);
FullName = findViewById(R.id.fullname);
UserName = findViewById(R.id.username);
Email = findViewById(R.id.email);
Password = findViewById(R.id.password);
}
#Override
public void onClick(View v) {
switch (v.getId()){
case R.id.login:
startActivity(new Intent(this, Login.class));
break;
case R.id.submit:
startActivity( new Intent(this,Login.class));
break;
}
}
private void submit(){
String email = Email.getEditText().getText().toString().trim();
String password = Password.getEditText().getText().toString().trim();
String fullName = FullName.getEditText().getText().toString().trim();
String username = UserName.getEditText().getText().toString().trim();
if (fullName.isEmpty()){
FullName.setError("Full Name is required!");
FullName.requestFocus();
return;
}
if (username.isEmpty()){
UserName.setError("User Name is required!");
UserName.requestFocus();
return;
}
if (password.isEmpty()){
Password.setError("Password is required!");
Password.requestFocus();
return;
}
if (email.isEmpty()){
Email.setError( "Email is required!" );
Email.requestFocus();
return;
}
if (!Patterns.EMAIL_ADDRESS.matcher(email).matches()){
Email.setError("Please provide valid Email!");
Email.requestFocus();
return;
}
if (password.length() < 6){
Password.setError("Min password length should be six characters!");
Password.requestFocus();
return;
}
mAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener( new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if (task.isSuccessful()){
User user = new User (fullName,email,username,password);
FirebaseDatabase.getInstance().getReference("user")
.child( FirebaseAuth.getInstance().getCurrentUser().getUid() )
.setValue( user ).addOnCompleteListener( new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task) {
if (task.isSuccessful()){
Toast.makeText( SignUp.this, "Successfully registered", Toast.LENGTH_LONG ).show();
if (task.isSuccessful()){
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if (user.isEmailVerified()){
startActivity(new Intent(SignUp.this, Login.class));
}else{
user.sendEmailVerification();
Toast.makeText(SignUp.this, "Check your email to verify your account!", Toast.LENGTH_LONG).show();
}
}startActivity(new Intent(SignUp.this,Login.class));
}else{
Toast.makeText( SignUp.this,"Unable to register!", Toast.LENGTH_LONG ).show();
}
}
} );
}else{
Toast.makeText( SignUp.this,"Unable to register!", Toast.LENGTH_LONG ).show();
}
}
} );
} }
I am developing an app on android studio and need to redirect clients and personal trainers to two different activities based on their role. Personal Trainers need to be directed to PTNoticeboardActivity and clients to NoticeboardActivity. Any suggestion on how to do this, here is my login code:
public class MainActivity extends AppCompatActivity {
private FirebaseAuth firebaseAuth;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
firebaseAuth = FirebaseAuth.getInstance();
}
public void loginUser(View View){
String email = ((EditText) findViewById(R.id.editText_Log_email)).getText().toString();
String password = ((EditText) findViewById(R.id.editText_Log_password)).getText().toString();
if(TextUtils.isEmpty(email)){
Toast.makeText(this, "Please enter email", Toast.LENGTH_LONG).show();
return;
}
if (TextUtils.isEmpty(password)){
Toast.makeText(this, "Please Enter Password", Toast.LENGTH_LONG).show();
return;
}
firebaseAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(MainActivity.this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if(task.isSuccessful()){
Toast.makeText(MainActivity.this, "Login Successful", Toast.LENGTH_LONG).show();
// startActivity(new Intent(getApplicationContext(), NoticeBoardActivity.class));
// finish();
} else {
Toast.makeText(MainActivity.this, "Login Unsuccessful", Toast.LENGTH_LONG).show();
}
}
});
}
}
Here is my register activity code below:
public class RegisterActivity extends AppCompatActivity {
EditText txt_fullname, txt_email, txt_mobilenumber, txt_repassword,
txt_password;
Button btn_register;
RadioButton radioJobClient, radioJobPT;
DatabaseReference databaseReference;
FirebaseDatabase firebaseDatabase;
String job ="";
FirebaseAuth firebaseAuth;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
txt_fullname = (EditText) findViewById(R.id.editText_fullname);
txt_email = (EditText) findViewById(R.id.editText_UserEmail);
txt_password = (EditText) findViewById(R.id.editText_Password);
txt_repassword = (EditText) findViewById(R.id.editText_rePassword);
txt_mobilenumber = (EditText) findViewById(R.id.mobilenumber);
btn_register = (Button) findViewById(R.id.button_reg);
radioJobClient = (RadioButton) findViewById(R.id.radio_Client);
radioJobPT = (RadioButton) findViewById(R.id.radio_PersonalTrainer);
databaseReference = FirebaseDatabase.getInstance().getReference("User");
// new code
firebaseAuth = FirebaseAuth.getInstance();
btn_register.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final String fullname = txt_fullname.getText().toString();
final String email = txt_email.getText().toString();
final String mobilenumber = txt_mobilenumber.getText().toString();
final String password = txt_password.getText().toString();
final String rePassword = txt_repassword.getText().toString();
if (radioJobClient.isChecked()){
job = "Client";
}
if (radioJobPT.isChecked()){
job = "PT";
}
if (TextUtils.isEmpty(email)){
Toast.makeText(RegisterActivity.this, "Please enter Email", Toast.LENGTH_LONG).show();
}
if (TextUtils.isEmpty(fullname)){
Toast.makeText(RegisterActivity.this, "Please enter fullname", Toast.LENGTH_LONG).show();
}
if (TextUtils.isEmpty(password)){
Toast.makeText(RegisterActivity.this, "Please enter password", Toast.LENGTH_LONG).show();
}
firebaseAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(RegisterActivity.this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
User user = new User(
fullname,
email,
mobilenumber,
password,
job
);
FirebaseDatabase.getInstance().getReference("User")
.child(FirebaseAuth.getInstance().getCurrentUser().getUid())
.setValue(user).addOnCompleteListener(new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task) {
Toast.makeText(RegisterActivity.this, "Registration Complete", Toast.LENGTH_SHORT).show();
startActivity(new Intent(getApplicationContext(),MainActivity.class));
}
});
} else {
Toast.makeText(RegisterActivity.this, "Registration Unsuccessful", Toast.LENGTH_LONG).show();
}
// ...
}
});
}
});
}
public void goLogin (View view){
startActivity(new Intent(RegisterActivity.this, MainActivity.class));
}
}
Database structure:
This is the most efficient way to do it:
When your user has created an account, create a child node in the firebase database as role with value as per the user. [could be client or personal trainer]
Then when your activity starts, fetch the value from the database like this:
First of all add a LOGIN BUTTON toyour login activity. When user presses that then only the login thing will take place.
Here is your modified MainActivity.java:
public class MainActivity extends AppCompatActivity {
private FirebaseAuth firebaseAuth;
String userRole;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
firebaseAuth = FirebaseAuth.getInstance();
btnLogin = findViewById(R.id.btn_login_resource);
btnLogin.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String email = ((EditText) findViewById(R.id.editText_Log_email)).getText().toString();
String password = ((EditText) findViewById(R.id.editText_Log_password)).getText().toString();
if(TextUtils.isEmpty(email)){
Toast.makeText(this, "Please enter email", Toast.LENGTH_LONG).show();
return;
}
else if (TextUtils.isEmpty(password)){
Toast.makeText(this, "Please Enter Password", Toast.LENGTH_LONG).show();
return;
}
else{
firebaseAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(MainActivity.this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if(task.isSuccessful()){
Toast.makeText(MainActivity.this, "Login Successful", Toast.LENGTH_LONG).show();
jobRef = FirebaseDatabase.getInstance().getReference().child("User").child(pAuth.getCurrentUser().getUid()).child("job");
jobRef.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot dataSnapshot) {
try {
userRole = dataSnapshot.getValue().toString();
if(userRole.equals("Client")){
startActivity(new Intent(MainActivity.this, NoticeboardActivity.class);
}
else {
startActivity(new Intent(MainActivity.this, PTNoticeboardActivity.class);
}
}catch (Throwable e){
Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_SHORT).show();
}
}
#Override
public void onCancelled(#NonNull DatabaseError databaseError) {
Toast.makeText(getApplicationContext(), databaseError.toString(), Toast.LENGTH_SHORT).show();
}
});
} else {
Toast.makeText(MainActivity.this, "Login Unsuccessful", Toast.LENGTH_LONG).show();
}
}
});
}
}
}
});
.
Now one thing to care about is that anyone can reverse-engineer this code and illegally can get access to the data. So make sure the data in each activity is hosted in Firebase and you have set the appropriate firebase rules. If you want me to elaborate please let me know in the comments down below.
User gets Registered Successfully and in LoginActivity after filling User details while Authenticating it gives
"Failed to send DDMS packet REAQ to debugger (-1 of 20): Broken pipe"
Error in LogCat.
signup.java -> signUP_btn ClickListener
public void signingup(View view) {
uid = findViewById(R.id.userbox);
repwd = findViewById(R.id.repwd);
mail = findViewById(R.id.mail);
pwd = findViewById(R.id.pwd);
mylayout = findViewById(R.id.signuplayout);
String username = uid.getText().toString();
String password = pwd.getText().toString();
String rePassword = repwd.getText().toString();
String email = mail.getText().toString();
if (username.equals("")) {
Toast.makeText(this, "Invalid Username!!", Toast.LENGTH_LONG).show();
} else if (password.equals("")) {
Toast.makeText(this, "Invalid Password!!", Toast.LENGTH_LONG).show();
} else if (!password.equals(rePassword)) {
Toast.makeText(this, "Password should Match!!", Toast.LENGTH_LONG).show();
} else if (email.equals("")) {
Toast.makeText(this, "Invalid Email Id!!", Toast.LENGTH_LONG).show();
} else {
firebaseAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
try {
//check if successful
if (task.isSuccessful()) {
//User is successfully registered and logged in
//start Profile Activity here
Toast.makeText(signup.this, "registration successful",
Toast.LENGTH_SHORT).show();
finish();
startActivity(new Intent(getApplicationContext(), LoginActiviity.class));
}else{
Log.d("Error", ": "+task.getException().toString());
Toast.makeText(signup.this, "Couldn't register, try again",
Toast.LENGTH_SHORT).show();
}
}catch (Exception e){
e.printStackTrace();
}
}
});
}
}
LoginActivity.java
public class LoginActiviity extends AppCompatActivity {
TextView welcome,signsub,signText,reset;
EditText user,pwd;
Button signing;
ImageView loginLogo;
Animation anim,headtext,body_text,body_text2,body_text3;
private FirebaseAuth firebaseAuth;
private FirebaseUser currentUser;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login_activiity);
Typeface MRegular = Typeface.createFromAsset(getAssets(),"fonts/MRegular.ttf");
Typeface MMedium = Typeface.createFromAsset(getAssets(),"fonts/MMedium.ttf");
Typeface MLight = Typeface.createFromAsset(getAssets(),"fonts/MLight.ttf");
welcome= findViewById(R.id.welcome);
signsub= findViewById(R.id.signsub);
signText= findViewById(R.id.signText);
reset= findViewById(R.id.reset);
user= findViewById(R.id.userbox);
pwd= findViewById(R.id.pwd);
signing= findViewById(R.id.signBtn);
loginLogo= findViewById(R.id.login_logo);
welcome.setTypeface(MRegular);
signsub.setTypeface(MLight);
signText.setTypeface(MMedium);
reset.setTypeface(MLight);
user.setTypeface(MLight);
pwd.setTypeface(MLight);
signing.setTypeface(MMedium);
anim= AnimationUtils.loadAnimation(this,R.anim.sm_tobig);
loginLogo.startAnimation(anim);
headtext= AnimationUtils.loadAnimation(this,R.anim.head_text);
welcome.startAnimation(headtext);
signsub.startAnimation(headtext);
body_text= AnimationUtils.loadAnimation(this,R.anim.body_text);
body_text2= AnimationUtils.loadAnimation(this,R.anim.body_text2);
body_text3= AnimationUtils.loadAnimation(this,R.anim.body_text3);
user.startAnimation(body_text);
pwd.startAnimation(body_text2);
signing.startAnimation(body_text3);
reset.startAnimation(body_text3);
firebaseAuth= FirebaseAuth.getInstance();
reset.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(LoginActiviity.this,signup.class);
startActivity(intent);
}
});
}
public void signingin(View view) {
user = findViewById(R.id.userbox);
pwd = findViewById(R.id.pwd);
String Email = user.getText().toString().trim();
String Password = pwd.getText().toString().trim();
firebaseAuth.signInWithEmailAndPassword(Email, Password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if (task.isSuccessful()){
currentUser = firebaseAuth.getCurrentUser();
Log.d("Error", "onComplete: "+task.toString()+currentUser);
startActivity(new Intent(getApplicationContext(),
RecyclerView.class));
}else {
Toast.makeText(LoginActiviity.this, "couldn't login",
Toast.LENGTH_SHORT).show();
}
}
});
}
}
Here in LoginActivity userbox is used for email.
I am trying to make registration to a App in Firebase, but it keeps on saying Unsuccessful.
Here is my code.
public class RegisterActivity extends AppCompatActivity implements View.OnClickListener {
private EditText etEmail;
private EditText etPassword;
private ProgressDialog progressDialog;
private FirebaseAuth firebaseAuth;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
firebaseAuth = FirebaseAuth.getInstance();
if (firebaseAuth.getCurrentUser() != null){
//Start profile activity here.
finish();
startActivity(new Intent(getApplicationContext(), HomeActivity.class));
}
progressDialog = new ProgressDialog(this);
etEmail = (EditText) findViewById(R.id.editTextEmail);
etPassword = (EditText) findViewById(R.id.editTextPassword);
Button btnRegister = (Button) findViewById(R.id.buttonRegister);
assert btnRegister != null;
btnRegister.setOnClickListener(this);
}
#Override
public void onClick(View v) {
registerUser();
}
private void registerUser(){
String email = etEmail.getText().toString().trim();
String password = etPassword.getText().toString().trim();
if (TextUtils.isEmpty(email)){
//Email is empty. Create a toast to enter a email.
Toast.makeText(this, "Please enter your email address.", Toast.LENGTH_SHORT).show();
// return to the email field.
return;
}
if (TextUtils.isEmpty(password)){
//Password is empty. Create a toast to enter a password.
Toast.makeText(this, "Please enter your password.", Toast.LENGTH_SHORT).show();
// return to the password field.
return;
}
progressDialog.setMessage("Registration on Process...");
progressDialog.show();
firebaseAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if (task.isSuccessful()){
//User is successfully registered.
Toast.makeText(RegisterActivity.this, "Registration is successful.", Toast.LENGTH_SHORT).show();
//Log in and User will start profile activity.
finish();
startActivity(new Intent(getApplicationContext(), HomeActivity.class));
}else{
progressDialog.dismiss();
Toast.makeText(RegisterActivity.this, "Registration failed. Please try again.", Toast.LENGTH_SHORT).show();
}
}
});
}
}
I tried Login Activity with an email, that I manually created in FirebaseAuth and it was successful. But the registration activity is regularly unsuccessful.
I couldn't find any error in the code. Can you help me please?