我无法将用户数据从注册活动代码发送到实时。我尝试了不同的方法,并确保所有连接都是正确的,但信息仍然没有到达实时。我正在使用的Gmail只能达到身份验证。我怀疑问题出在我的代码上。下面是相关的代码片段:
java注册
private FirebaseAuth mAuth;
private FirebaseAuth.AuthStateListener authStateListener;
ActivitySignUpBinding binding;
DatabaseReference usersRef = FirebaseDatabase.getInstance().getReference("Users");
ProgressDialog dialog;
EditText emailEditText;
EditText passwordEditText;
EditText phoneEditText;
EditText firstNameEditText;
EditText lastNameEditText;
EditText CompassE;
private String email;
private String password;
private String phone;
private String firstName;
private String lastName;
private String repass;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sign_up);
mAuth = FirebaseAuth.getInstance();
dialog = new ProgressDialog(sign_up.this);
dialog.setTitle("Created Account");
dialog.setMessage("We created your account");
binding = ActivitySignUpBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
emailEditText = binding.Textemail;
passwordEditText = binding.Textpass;
phoneEditText = binding.Textphone;
firstNameEditText = binding.Textname;
lastNameEditText = binding.Textlast;
CompassE = binding.repass;
findViewById(R.id.button1).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
email = emailEditText.getText().toString().trim();
password = passwordEditText.getText().toString().trim();
phone = phoneEditText.getText().toString().trim();
firstName = firstNameEditText.getText().toString().trim();
lastName = lastNameEditText.getText().toString().trim();
repass = CompassE.getText().toString().trim();
// Registration logic
mAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
String userId = mAuth.getCurrentUser().getUid();
String email = emailEditText.getText().toString();
String refer = email.substring(0, email.lastIndexOf("@"));
String referCode = refer.replace(".", "");
DatabaseReference usersRef = FirebaseDatabase.getInstance().getReference("Users");
HashMap<String, Object> map = new HashMap<>();
map.put("name", firstNameEditText.getText().toString());
map.put("phone", phoneEditText.getText().toString());
map.put("mail", emailEditText.getText().toString());
map.put("password", passwordEditText.getText().toString());
map.put("refer code", referCode);
map.put("profile", "https://firebasestorage.googleapis.com/v0/b/escar-95491.appspot.com/o/placeholder.png?alt=media&token=92d82a11-fb0e-4476-9170-a4b99b8baa13\n");
map.put("cis", 20);
map.put("sps", 4);
// Send the data to the database
usersRef.child(mAuth.getCurrentUser().getUid()).setValue(map);
Intent intent = new Intent(sign_up.this, testMain.class);
startActivity(intent);
finish();
Toast.makeText(sign_up.this, "Your account has been created", Toast.LENGTH_SHORT).show();
DatabaseReference databaseRef = FirebaseDatabase.getInstance().getReference("Users");
databaseRef.child(mAuth.getCurrentUser().getUid()).setValue(map);
} else {
Toast.makeText(sign_up.this, "Error: " + task.getException().getMessage(), Toast.LENGTH_SHORT).show();
}
}
});
}
});
用户Java类
public class User {
String name,email,password,refercode,profile,cis,sps,phone;
public User(String name,String email,String password,String refercode,String profile,String cis,String sps,String phone){
this.name=name;
this.email=email;
this.password=password;
this.refercode=refercode;
this.profile=profile;
this.cis=cis;
this.sps=sps;
this.phone=phone;
}
public User() {
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getRefercode() {
return refercode;
}
public void setRefercode(String refercode) {
this.refercode = refercode;
}
public String getProfile() {
return profile;
}
public void setProfile(String profile) {
this.profile = profile;
}
public String getCis() {
return cis;
}
public void setCis(String cis) {
this.cis = cis;
}
public String getSps() {
return sps;
}
public void setSps(String sps) {
this.sps = sps;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
}
安全规则:
{
"rules": {
".read": true,
".write": true
}
}
1条答案
按热度按时间l5tcr1uw1#
你好,正如我所说,不是所有的代码工作,只是gmail达到身份验证,但没有在代码(没有什么用户或IM写的编辑文本达到实时),有没有错误的代码只是这警告也许有问题的代码不要使此信息发送到ral时间,但我不知道它