5
votes

I want to write data in Firebase Realtime Database from Android.I did the following things.

  1. Created Project in firebase

  2. Configured and downloaded the json file and pasted in the app directory

  3. Did all others stuffs.

  4. EDITED THE RULES CORRECTLY

Then I am trying to run the most simplest code provided in the docs

FirebaseDatabase database = FirebaseDatabase.getInstance();
    DatabaseReference myRef = database.getReference("message");

    myRef.setValue("Hello, World!");

Still not working. The database is still showing empty. Somebody please help. Thank you

5
Do you see any errors such as "permission denied" in the logs? - Adam Piziak
By default, the rules are set to only allow reading and writing by an authenticated user. - Jay
Did you find a solution to this? - MrPool

5 Answers

0
votes

Check the rules in the settings of the database. By default only is allowed to write and read to authorized users. Change it to:

 {
  "rules": {
    ".read": true,
    ".write": true
  }
}

Maybe that could solve your problem.

0
votes

You could add te following code to test what is happening:

dataReference.setValue(value, new DatabaseReference.CompletionListener() {
    @Override
    public void onComplete(DatabaseError databaseError, DatabaseReference dataReference) {

    }
});
0
votes

change rules

{
  "rules": {
    ".read": true,
    ".write": true
  }
}
0
votes

Check your read and write rules

"rules": ".read": "auth == null", ".write": "auth == null"

this rule will allow only if user is not signed in.

writing in database FirebaseDatabase.getInstance().getReference().child("users").setValue("value");

0
votes

Here's some code to try:

private DatabaseReference mDatabase;
mDatabase = FirebaseDatabase.getInstance().getReference();
mDatabase.child("messages").setValue("Hello, World");

If that doesnt work, then either there's a rules problem (which I think you addressed) or there's an Firebase initialization problem in the app.