未创建Firebase表

时间:2018-09-28 08:20:06

标签: android firebase firebase-realtime-database firebase-authentication

我想创建一个Firebase表以及名称Users和属性Name,Email,Password和默认ID,并且还要注册Firebase身份验证。但是当我运行该应用程序时,它显示了空数据。

Firebase中显示的数据为 Data Created in Firebase

这是我的注册验证和在数据库中保存用户属性的代码。 此活动的主要目的是保存用户属性以及使用电子邮件创建新用户。

TextView TxtName,TxtEmail,TxtPassword;
Button BTNFB,BTNEMAIL;
FirebaseAuth mAuth;
ProgressDialog progressDialog;
DatabaseReference databaseNameRegistration;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_register);
    TxtName= findViewById(R.id.txtname);
    TxtEmail= findViewById(R.id.txtemail);
    BTNEMAIL= findViewById(R.id.btnregisteremail);
    TxtPassword= findViewById(R.id.txtpassword);
    progressDialog= new ProgressDialog(this);
    mAuth= FirebaseAuth.getInstance();
    databaseNameRegistration= FirebaseDatabase.getInstance().getReference("Child Safety");
    BTNEMAIL.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            FunRegisterUser();
        }
    });
}
private void FunRegisterUser() {
    final String email = TxtEmail.getText().toString().trim().toLowerCase();
    final String password = TxtPassword.getText().toString().trim().toLowerCase();
    final String name= TxtName.getText().toString().trim().toLowerCase();
    if (TextUtils.isEmpty(email)|| !android.util.Patterns.EMAIL_ADDRESS.matcher(email).matches()){
        TxtEmail.setError("Please Enter a Valid Email");
        return;
    }
    if (TextUtils.isEmpty(password)|| password.length() < 4 || password.length() > 10){
        TxtPassword.setError("Enter The Password");
        return;
    }
    if(TextUtils.isEmpty(name))
    {
        TxtName.setError("Please Enter a Valid Email");
        return;
    }
    progressDialog.setMessage("Registering User...");
    progressDialog.show();
    mAuth.createUserWithEmailAndPassword(email,password)
        .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
            @Override
            public void onComplete(@NonNull Task<AuthResult> task) {
                if (task.isSuccessful()){
                    String id = databaseNameRegistration.push().getKey();
                    ClassUsersDetail classUsersDetail= new ClassUsersDetail(id,name,email,password);
                    databaseNameRegistration.child(id).setValue(classUsersDetail);
                    Toast.makeText(RegisterActivity.this, "Registered Successfully", Toast.LENGTH_LONG).show();
                }else {
                    Toast.makeText(RegisterActivity.this, "Not Registered...",Toast.LENGTH_LONG).show();
                }
                progressDialog.dismiss();
            }
        });
}

这里是活动的类,用于获取和设置数据

public class ClassUsersDetail {
    String TxtName;
    String TxtEmail;
    String TxtPassword;
    String UserId;

    public ClassUsersDetail(){
    }

    public ClassUsersDetail(String txtName, String txtEmail, String txtPassword, String userId) {
        TxtName = txtName;
        TxtEmail = txtEmail;
        TxtPassword = txtPassword;
        UserId = userId;
    }

    public String getTxtName() {
        return TxtName;
    }

    public String getTxtEmail() {
        return TxtEmail;
    }

    public String getTxtPassword() {
        return TxtPassword;
    }

    public String getUserId() {
        return UserId;
    }

    public void setTxtName(String txtName) {
        TxtName = txtName;
    }

    public void setTxtEmail(String txtEmail) {
        TxtEmail = txtEmail;
    }

    public void setTxtPassword(String txtPassword) {
        TxtPassword = txtPassword;
    }

    public void setUserId(String userId) {
        UserId = userId;
    }
}

我要做的是将用户及其姓名,电子邮件和密码保存在数据库中。

0 个答案:

没有答案