-2

I am working on android with firebase database. I have done all the settings correct and injected value to DB. But I have an issue:

W/RepoOperation: setValue at /demo/-L5xSv3ICHg2BFupI7DG failed: DatabaseError: Permission denied

My code :

package app.com.test;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;

import java.nio.file.Files;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    Button b;
    EditText name;
    DatabaseReference rootRef,demoRef;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        b= findViewById(R.id.button2);
        name= findViewById(R.id.editText);
        //age=findViewById(R.id.editText2);
        rootRef= FirebaseDatabase.getInstance().getReference();
        demoRef=rootRef.child("demo");

        b.setOnClickListener(this);


    }

    @Override
    public void onClick(View view) {

        String n=name.getText().toString();

        //int a = Integer.parseInt(age.getText().toString());


        demoRef.push().setValue(n);
        //demoRef.push().setValue(a);
        Toast.makeText(this, "DB inserted", Toast.LENGTH_LONG).show();

    }
}
James Z
  • 12,209
  • 10
  • 24
  • 44

1 Answers1

0

Your issue is regarding firebase writing and reading permission rules, So for the solution, you need to update your firebase rules Like blow from firebase console.

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

Follow following step for update rules

  • open firebase console
  • select Database option from Develope section
  • Then after select Rules Tab and update rules as above

Note: If you want to restrict unknown user then you need to implement authentication in your app using of like google, facebook, e.t.c,

Dhaval Solanki
  • 4,589
  • 1
  • 23
  • 39