Firebase不会接收电子邮件/密码身份验证

时间:2018-03-05 01:08:06

标签: java android firebase firebase-authentication

我的代码运行完美,我没有错误,我通过调试运行应用程序,没有任何显示。所以我已经检查过我是否拥有最新的firebase依赖项并且我已经更新了Google Play服务但由于某些原因我的应用程序不会将用户注册到Firebase。

EditText registerEmail, registerPassword;

private FirebaseAuth mAuth;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_register);

    registerEmail = (EditText) findViewById(R.id.registerEmail);
    registerPassword = (EditText) findViewById(R.id.registerPassword);

    mAuth = FirebaseAuth.getInstance();

    findViewById(R.id.registerButton).setOnClickListener(this);
}

private void registerUser() {
    String email = registerEmail.getText().toString().trim();
    String password = registerPassword.getText().toString().trim();

    if(email.isEmpty()) {
        registerEmail.setError("Email is required");
        registerEmail.requestFocus();
        return;
    }
    if(!Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
        registerEmail.setError("Enter a valid email");
        registerEmail.requestFocus();
        return;
    }
    if(password.isEmpty()) {
        registerPassword.setError("Password is required");
        registerPassword.requestFocus();
        return;
    }
    if(password.length() < 8) {
        registerPassword.setError("Minimum 8 characters required");
        registerPassword.requestFocus();
        return;
    }

    mAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
        @Override
        public void onComplete(@NonNull Task<AuthResult> task) {
            if(task.isSuccessful()) {
                Toast.makeText(getApplicationContext(), "successful", Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(getApplicationContext(), "not successful", Toast.LENGTH_SHORT).show();
            }
        }
    });

}

@Override
public void onClick(View view) {
    switch (view.getId()) {
        case R.id.registerButton:
            registerUser();
            //startActivity(new Intent(this, MainActivity.class));

            break;
        case R.id.loginTextView:

            startActivity(new Intent(this, Login.class));

            break;
    }
}

我收到“不成功”的消息,因此问题必须在mAuth.createUserWithEmailAndPassword()的某处。提前谢谢。

1 个答案:

答案 0 :(得分:0)

您获得的错误非常具有误导性,并且在线寻找解决方案我发现无数人在努力解决这个问题,但没有人提到启用Google Identity Toolkit API 这为我解决了这个问题