Unable to upload data from android studio to firebase real time database

My dependencies list are

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    testImplementation 'junit:junit:4.12'

    implementation 'com.android.support:design:28.0.0'
    implementation 'androidx.appcompat:appcompat:1.0.0'

    // Displaying images
    implementation 'com.github.bumptech.glide:glide:3.6.1'
    implementation platform('com.google.firebase:firebase-bom:26.8.0')
    implementation 'com.google.firebase:firebase-database:19.7.0'
    implementation 'com.google.firebase:firebase-auth'
    implementation 'com.google.firebase:firebase-analytics'
}

I also connected to the firebase and created Real Time database. I also set the firebase authentication rule to true

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

In the MainActivity first i declared 2 variables

private FirebaseDatabase mFirebaseDatabase;
private DatabaseReference mMessagesDatabaseReference;

and then in OnCreate method I posted this

mFirebaseDatabase=FirebaseDatabase.getInstance();
mMessagesDatabaseReference=mFirebaseDatabase.getReference();

After that i called database reference to set string value on the database.

 FriendlyMessage friendlyMessage = new FriendlyMessage(mMessageEditText.getText().toString(), mUsername, null);
                String data=friendlyMessage.getText();
                mMessagesDatabaseReference.setValue(data);

This is my FriendlyMessage.java class

package com.google.firebase.udacity.friendlychat;

public class FriendlyMessage {

    private String text;
    private String name;
    private String photoUrl;

    public FriendlyMessage() {
    }

    public FriendlyMessage(String text, String name, String photoUrl) {
        this.text = text;
        this.name = name;
        this.photoUrl = photoUrl;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPhotoUrl() {
        return photoUrl;
    }

    public void setPhotoUrl(String photoUrl) {
        this.photoUrl = photoUrl;
    }
}

But every time firebase is showing this thing

This is my Firebase Realtime database

please someone help me

Answer

Your security rules allow anyone to write any data they want under the /Users node in the database. But your code is trying to write directly under the root, where nobody has been granted any permission.

You most likely were looking to allow all read and writes at the root of your database, which can be done with:

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

After you’ve verified that this works, I highly recommend studying the documentation on security rules to learn how (and why) to write rules that match your exact needs.