我已经创建了用户配置文件并与 fireabse 连接,但保存 btn 数据后未显示我在 firebase 中的实时数据库
我已经尝试了很多次并且
这是提供的实时数据库规则
"rules": {
".read": "auth != null",
".write": "auth != null"
}
}
btnsaveprofile.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
username = edtxtusername.getText().toString().trim();
profession = spinnerprofession.getSelectedItem().toString();
if (username.isEmpty()){
Toast.makeText(getApplicationContext(), "Please Enter Your Name", Toast.LENGTH_SHORT).show();
} else if (profession.equals(getString(R.string.select_profession))) {
Toast.makeText(getApplicationContext(), "Please Select Your Profession", Toast.LENGTH_SHORT).show();
} else {
mprogressbarofsaveprofile.setVisibility(View.VISIBLE);
btnsaveprofile.setVisibility(View.INVISIBLE);
firebaseAuth = FirebaseAuth.getInstance();
databaseReference = FirebaseDatabase.getInstance().getReference("users");
String userId = databaseReference.push().getKey();
User user = new User(username, profession);
databaseReference.child(userId).setValue(user);
Toast.makeText(getApplicationContext(), "Success", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(getApplicationContext(), NexusHome.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
btnsaveprofile.setVisibility(View.VISIBLE);
mprogressbarofsaveprofile.setVisibility(View.INVISIBLE);
}
}
});
这是 User.class java 代码
public class User {
private String username;
private String profession;
public User() {
}
public User(String username, String profession) {
this.username = username;
this.profession = profession;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getProfession() {
return profession;
}
public void setProfession(String profession) {
this.profession = profession;
}
}
请帮助我更正此代码,我可以将数据保存在 firebase 中吗
"rules": {
".read": "true",
".write": "true",
}