1

I was trying to connect to the Authentication in the firebase using email and password but everytime I enter email and password I get registration failed. Here's my code :

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

private Button buttonRegsiter;
private EditText editTextEmail;
private EditText editTextPassword;

private ProgressDialog progressDialog;
private FirebaseAuth firebaseAuth;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    System.out.print("In main");
    progressDialog = new ProgressDialog(this);
    firebaseAuth = FirebaseAuth.getInstance();

    buttonRegsiter = (Button) findViewById(R.id.registerUserButton);
    editTextEmail = (EditText) findViewById(R.id.editTextEmail);
    editTextPassword = (EditText) findViewById(R.id.editTextpassword);

    buttonRegsiter.setOnClickListener(this);

}

private void registerUser(){
    String email = editTextEmail.getText().toString().trim();
    String password = editTextPassword.getText().toString().trim();

    if(TextUtils.isEmpty(email)){
        //email field is empty
        Toast.makeText(this,"Please enter email",Toast.LENGTH_LONG).show();
        return;
    }

    if(TextUtils.isEmpty(password)){
        //password is empty
        Toast.makeText(this,"Please enter your password",Toast.LENGTH_LONG).show();
        return;
    }

    //if validations are ok
    //show a progressbar

    progressDialog.setMessage("Registering user...");
    progressDialog.show();

    firebaseAuth.createUserWithEmailAndPassword(email,password)
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
            @Override
                public void onComplete(@NonNull Task<AuthResult> task){
                if(task.isSuccessful()){
                    Toast.makeText(MainActivity.this,"Registration successful",Toast.LENGTH_LONG).show();
                }
                else{
                    Toast.makeText(MainActivity.this,"Failed to register. Please try again", Toast.LENGTH_LONG).show();
            }
              progressDialog.dismiss();
            }});
}


@Override
public void onClick(View view) {
    if(view == buttonRegsiter){
        registerUser();
    }
}
}  

Can you let me know what is the error in my code?

This is the error I am getting on logcat

01-03 23:32:49.811 1570-1620/system_process E/SoundPool: error loading /system/media/audio/ui/Effect_Tick.ogg

Shubhamhackz
  • 7,333
  • 7
  • 50
  • 71
  • Check in https://stackoverflow.com/questions/23180638/how-fix-this-on-logcat-error-loading-system-media-audio-ui-effect-tick-og – KDD Jan 04 '18 at 05:26
  • Are you test app on emulator? – Hemant Parmar Jan 04 '18 at 05:29
  • may be its emulator issue, have look [this](https://stackoverflow.com/q/23180638/5110595) – Hemant Parmar Jan 04 '18 at 05:30
  • First thing is to know what is the issue `FirebaseAuthException e = (FirebaseAuthException )task.getException();` `Log.e("LoginActivity", "Failed Registration", e);` write this in the else case. – Sunil Sunny Jan 04 '18 at 05:31

3 Answers3

0

The problem is, Effect_Tick.ogg is used by System for touch sounds.

  1. Either you can try using any other sound or
  2. Go to Sound Settings of your device & turn off "Touch Sounds", then restart your device/emulator.
Sneh Pandya
  • 8,197
  • 7
  • 35
  • 50
0

Please Make sure that you have enabled signin method using email/password in firebase dashboard

Tejas Pandya
  • 3,987
  • 1
  • 26
  • 51
0

I am using firebase for signup via email and password . its may be different method but working for me .

public class MainActivity extends AppCompatActivity {

    private int SIGN_IN_REQUEST_CODE=4;
    private FirebaseAuth mAuth;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        FirebaseApp.initializeApp(this);
        setContentView(R.layout.activity_main);
        mAuth = FirebaseAuth.getInstance();

        if(FirebaseAuth.getInstance().getCurrentUser() == null) {
            // Start sign in/sign up activity
            startActivityForResult(
                    AuthUI.getInstance()
                            .createSignInIntentBuilder()
                            .build(),
                    SIGN_IN_REQUEST_CODE
            );
        } else {
            // User is already signed in. Therefore, display
            // a welcome Toast
            Toast.makeText(this,
                    "Welcome " + FirebaseAuth.getInstance()
                            .getCurrentUser()
                            .getDisplayName(),
                    Toast.LENGTH_LONG)
                    .show();

            // Load chat room contents
            displayChatMessages();
        }

    }

    private void displayChatMessages() {

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if(requestCode == SIGN_IN_REQUEST_CODE) {
            if(resultCode == RESULT_OK) {
                Toast.makeText(this,
                        "Successfully signed in. Welcome!",
                        Toast.LENGTH_LONG)
                        .show();
                displayChatMessages();
            } else {
                Toast.makeText(this,
                        "We couldn't sign you in. Please try again later.",
                        Toast.LENGTH_LONG)
                        .show();

                // Close the app
                finish();
            }
        }
    }
}

add this extra dependencies in (module:app), put apply plugin at bottom of (module:aap)

dependencies {
    compile 'com.google.firebase:firebase-core:9.2.0'
    compile 'com.google.firebase:firebase-auth:9.2.0'
    compile 'com.google.firebase:firebase-messaging:9.2.0'
    implementation 'com.firebaseui:firebase-ui:3.1.2'
}
apply plugin: 'com.google.gms.google-services'

and add this extra dependencies in Project level module.

dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'

        classpath 'com.google.gms:google-services:3.1.0'
    }

Please enabled signin method using email/password in firebase dashboard

iamkdblue
  • 3,448
  • 2
  • 25
  • 43
  • I tried doing this but the event log shows gradle build failed. Is it because I am using firebase version 11.0.4? dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) ..............compile 'com.google.firebase:firebase-auth:11.0.4' compile 'com.google.firebase:firebase-core:9.2.0' compile 'com.google.firebase:firebase-auth:9.2.0' implementation 'com.firebaseui:firebase-ui:3.1.2' } – Kinnari Manoj Sanghvi Jan 04 '18 at 19:10
  • don't use firebase version 11.0.4 , dont change anything in above code. – iamkdblue Jan 05 '18 at 05:21
  • I tried doing that. It gives an error saying use same versions. All gms/libraries should have exact version. two versions are found - 9.2.0 and 11.0.6. What does that mean? – Kinnari Manoj Sanghvi Jan 06 '18 at 04:13
  • it's not an error , its just warning . Run as it is don't change anything. – iamkdblue Jan 06 '18 at 04:33