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:
leafBox001lightSensor:6793currentState:false
then do the following:
DatabaseReference reference = FirebaseDatabase.getInstance().getReference("leafBox001");
reference.addListenerForSingleValueEvent(newValueEventListener() {
@OverridepublicvoidonDataChange(DataSnapshot dataSnapshot) {
String sensor = dataSnapshot.child("lightSensor").getValue().toString();
String currentState = dataSnapshot.child("currentState").getValue().toString();
}
@OverridepublicvoidonCancelled(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"