答案 0 :(得分:1)
假设oxygen_level
是Firebase root
的直接子项,要显示这些值,请使用以下代码:
DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
DatabaseReference oxygenLevelRef = rootRef.child("oxygen_level");
ValueEventListener eventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot ds : dataSnapshot.getChildren()) {
String oxygen_mg = ds.child("oxygen_mg").getValue(String.class);
String sensor_status = ds.child("sensor_status").getValue(String.class);
String time = ds.child("time").getValue(String.class);
Log.d("TAG", oxygen_mg + " / " + sensor_status + " / " + time);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {}
};
oxygenLevelRef.addListenerForSingleValueEvent(eventListener);