I am making an android app using the firebase Realtime database. My rules structure is given below:
{
// Allow anyone to read data, but only authenticated content owners can
// make changes to their data
"rules": {
"Users": {
"$uid": {
".read": true,
// or ".read": "auth.uid != null" for only authenticated users
".write": "auth.uid == $uid"
}
}
}
}
It means that a user should be signed in as an authenticated user to write some data. But when it comes to read no sign in is required.
Now I need to ignore the uid of the user to give free access to other users( i.e. without signing in).
This is the java code I am using currently to read data.
final Intent k = getIntent();
final String school = Objects.requireNonNull(k.getExtras()).getString("School");
final Intent i = getIntent();
final String roll = Objects.requireNonNull(i.getExtras()).getString("Roll");
myRef = myfire.getReference("Users")
.child("GcZoeK7JIbNWVOog6ZjUPiBfxwn2")// **I have problem here.**
.child(school).child(roll);
myRef.child("basic").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
String name = (String) dataSnapshot.child("fb01name").getValue().toString();
String number = (String) dataSnapshot.child("fb04roll").getValue().toString();
if(name == null){
Toast.makeText(getApplicationContext(),"Invalid",Toast.LENGTH_SHORT).show();
}
basic model = new basic(name,number);
tvName.setText(name);
tvRoll.setText(number);
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
});
I could not decide what to write instead of the first child to read any data without signing in.
.child("GcZoeK7JIbNWVOog6ZjUPiBfxwn2")
Please guide me How to ignore this child? Any help will be appreciated.
from How to read child nodes without mentioning parent node in firebase database within android studio?
No comments:
Post a Comment