我这里有一个简单的POJO课程:
@IgnoreExtraProperties
public class Poll {
private String Question;
private String Image_URL;
public Poll() {
}
public Poll(String Question, String Image_URL){
this.Question = Question;
this.Image_URL = Image_URL;
}
public String getQuestion() {
return Question;
}
public void setQuestion(String question) {
Question = question;
}
public String getImage_URL() {
return Image_URL;
}
public void setImage_URL(String image_URL) {
Image_URL = image_URL;
}
}
我正在尝试通过以下方法写入Firebase,并且Firebase数据库中根本没有发生任何事情,因此它不会编写或识别引用。它可能与我的Firebase / POJO映射有关,但我无法确定原因:
mSubmitPollCreation.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// //TODO: Need to determine if this is proper epoch - i.e. does it account for time zones
// Calendar c = Calendar.getInstance();
// final String epochTime = String.valueOf(c.getTimeInMillis());
// mEpochRef = mBaseRef.child("Poll").child(epochTime);
//TODO: Need to check if poll requirements are added, i.e. Question, Answer, ......
//check if image has been loaded first
if (resultImageURL != null){
Map<String, Object> imageURL = new HashMap<String, Object>();
imageURL.put("Image_URL", resultImageURL);
// mEpochRef.updateChildren(imageURL);
} else {
Toast.makeText(getApplicationContext(),getResources().getString(R.string.no_image_selected),Toast.LENGTH_LONG).show();
return;
}
Poll poll = new Poll(mCreatePollQuestion.getText().toString(), resultImageURL);
mBaseRef = FirebaseDatabase.getInstance().getReference();
mBaseRef.child("Polls").push().setValue(poll);
}
答案 0 :(得分:3)
首先检查安全规则,是否已启用写入权限...如果未启用写入权限...在以下链接中查找如何设置权限... https://firebase.google.com/docs/database/security/quickstart