好的,所以我希望有人可以帮助我解决这个问题,因为过去几天我一直在尝试多种不同的解决方案。在我的 Activity 中,我有一个 EditText 和一个 Button,我正在尝试将该用户输入写入 Firebase。运行应用程序时我没有收到任何错误,但是,当我按下按钮时,没有任何反应。
这是我的类(class):
private EditText userEmail;
Button sendInviteButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Firebase.setAndroidContext(this);
setContentView(R.layout.activity_user_registration);
userEmail = (EditText) findViewById(R.id.user_email);
sendInviteButton = (Button) findViewById(R.id.sendInviteButton);
}
public void btn(View view) {
sendInviteButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Firebase ref = new Firebase("https://app-1318.firebaseio.com/clients");
String enteredUserEmail = userEmail.getText().toString();
ref.child("userBackgroundCheck").setValue(enteredUserEmail);
}
});
}
我在 XML 中确实有一个按钮的 onClick,所以我真的不知道为什么没有将此数据发送到 Firebase。
最后,我们是否应该为这部分使用 Firebase 的根 URL?:
Firebase ref = new Firebase("https://app-1318.firebaseio.com/clients");
这将是:
Firebase ref = new Firebase("https://app-1318.firebaseio.com");
最佳答案
您是否尝试在实时数据库下添加规则。当您转到实时数据库时,单击规则选项卡。添加以下行
// These rules give anyone, even people who are not users of your app,
// read and write access to your database
{
"rules": {
".read": true,
".write": true
}
}
看看有没有效果!
另外,为什么要以旧方式存储数据。这是 new doc用于在实时数据库中保存数据。
关于java - 按下按钮时数据未写入 Firebase,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39546988/