I am using Firebase for the first time and I am attempting to read and write to the Realtime Database. However, when I completed Google's tutorial and ran my app the read/write method failed. Why would a simple read/write fail?
I made sure that the authentication was set to "allow read, write;". I checked my Gradle scripts as well and I didn't see anything missing at the project or the app level.
Code from tutorial:
private static final String TAG = "MainActivity";
...
writeReadDatabase()
...
public void writeReadDatabase()
{
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference("message");
myRef.setValue("first write and read");
myRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
String value = dataSnapshot.getValue(String.class);
Log.d(TAG, "Value is: " + value);
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
Log.w(TAG, "Failed to read value.", databaseError.toException());
}
});
}
Debug Logs:
W/SyncTree: Listen at /message failed: DatabaseError: Permission denied
W/RepoOperation: setValue at /message failed: DatabaseError: Permission denied
The database is just the default message saying the database is ready.
I'm trying to get the Logs to show up in Android Studio and for something to register in the database to see that it's working. I don't see a reason why permissions would be denied when no rules are set.
Edit:
*I was on Firestore.
Edit2: *My rules were set to false.
Edit3:
{
"rules": {
".read": true,
".write": true
}
}
I changed the rules and ran the app once more, the database works now.