我无法在myRef.push()。setValue()中使用字符串

时间:2019-02-23 21:25:40

标签: android firebase firebase-realtime-database

我需要将电子邮件上传到Firebase数据库,但是当我创建帐户时,它并没有在数据库中创建电子邮件,但是在Firebase身份验证中会创建

private void registrarUsuario(){

                final String email2 = TextEmail.getText().toString().trim();
                String password2 = pass.getText().toString().trim();
    //...

    public void onComplete(@NonNull Task<AuthResult> task) {
          if (task.isSuccessful()) { 
          Toast.makeText(getApplicationContext(), "Se ha registrado el usuario con el email: " + TextEmail.getText(), Toast.LENGTH_LONG).show();

    FirebaseDatabase database = FirebaseDatabase.getInstance();
    DatabaseReference myRef = database.getReference("people");

    myRef.push().setValue(email2);

2 个答案:

答案 0 :(得分:0)

尝试类似这样的方法。并检查是否有任何异常。 并在数据库规则中添加true读写。

ref.push.setValue(email, new Firebase.CompletionListener() {
    @Override
    public void onComplete(FirebaseError firebaseError, Firebase firebase) {
        if (firebaseError != null) {
            System.out.println("Data could not be saved. " + firebaseError.getMessage());
        } else {
            System.out.println("Data saved successfully.");
        }
    }
});

答案 1 :(得分:0)

我不确定这些符号**在您的代码myRef.push().setValue(email2**);中意味着什么
但这可能是您遇到问题的原因。

希望对您有帮助!