答案 0 :(得分:5)
刚试过这个,它确实有效!
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference reference = database.getReference("drivers");
Query query = reference.orderByChild("online").equalTo("true");
query.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Log.d(TAG, dataSnapshot.toString());
}
public void onCancelled(DatabaseError databaseError) { }
});
答案 1 :(得分:3)
我找到了问题的答案,感谢A. Omar和Frank van Puffelen的帮助:
DatabaseReference ref = FirebaseDatabase.getInstance()
.getReferenceFromUrl("https://<your-app>.firebaseio.com/drivers/");
ref.addValueEventListener(new ValueEventListener()
{
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot driverSnapshot: dataSnapshot.getChildren())
{
if(driverSnapshot.child("online").getValue().toString()=="true"){
Log.d(TAG, driverSnapshot.getKey() + " - " + driverSnapshot.child("online").getValue().toString());
}
}
}
public void onCancelled(FirebaseError firebaseError) {
}
});
这将仅打印在线用户,如:
2332424 - 是的