Skip to content Skip to sidebar Skip to footer

Can't Get Value From Firebase Database DataSnapshot

I have read many answers to this question, none solved my problem. ValueEventListener dataListener = new ValueEventListener() { @Override public void onDataChan

Solution 1:

Your database structure is like this:

 leafBox001
      lightSensor:6793
      currentState: false

then do the following:

DatabaseReference reference = FirebaseDatabase.getInstance().getReference("leafBox001");

reference.addListenerForSingleValueEvent(new ValueEventListener() {
 @Override
public void onDataChange(DataSnapshot dataSnapshot) {
      String sensor = dataSnapshot.child("lightSensor").getValue().toString();
      String currentState = dataSnapshot.child("currentState").getValue().toString();

}
@Override
public void onCancelled(DatabaseError databaseError) {
    }
});

The snapshot is at the key leafBox001 then you will be able to access the child of that key.


Post a Comment for "Can't Get Value From Firebase Database DataSnapshot"