在Firebase中检索特定用户的所有已接收消息

时间:2017-09-25 05:17:25

标签: android firebase firebase-realtime-database

如何从Firebase数据库中检索特定用户的所有收到的消息?

1 个答案:

答案 0 :(得分:0)

FirebaseDatabase database;
DatabaseReference databaseReference;
database = FirebaseDatabase.getInstance();
databaseReference = database.getReference("firebase_db_name);

DatabaseReference databaseReference = databaseReference.child("your_user");
        databaseReference.addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
              if (dataSnapshot != null) {
                  YOUR_OBJECT object =  
                              dataSnapshot.getValue(YOUR_OBJECT.class);
                  // todo in object you will get all your msgs
              }

            }

            @Override
            public void onCancelled(DatabaseError databaseError) {

            }
        });