检索当前用户值Firebase

时间:2018-08-01 18:55:13

标签: java firebase firebase-realtime-database

Image of my database structure

这是我的数据库的结构。在这里,我想登录后检索值以显示用户个人资料(当前登录的用户)。因此,我想获取部门(在此情况下为或C ),然后从列表中根据用户获取,然后获取用户的子代。例如 employee_type( 1或2 然后显示详细信息

这是代码:我尝试过但没有成功

databaseReference=FirebaseDatabase.getInstance().getReference().child("departmenmt");
databaseReference.addListenerForSingleValueEvent(new ValueEventListener() {
   @Override
    public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
     for(DataSnapshot datas: dataSnapshot.getChildren()){
       final String department_value=datas.getKey();

          databaseReference=FirebaseDatabase.getInstance().getReference().child("departmenmt").child(department_value).child("users");
            databaseReference.addListenerForSingleValueEvent(new ValueEventListener() {
              @Override
               public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                 for (DataSnapshot data: dataSnapshot.getChildren()){
                  final String Employee_type=data.getKey();        

                   currentuser= FirebaseAuth.getInstance().getCurrentUser();
                    String current_uid= currentuser.getUid();                               
                    databaseReference=FirebaseDatabase.getInstance().getReference().child("department").child(department_value).child("users").child(Employee_type).child(current_uid);
                    databaseReference.addValueEventListener(new ValueEventListener() {
                     @Override
                       public void onDataChange(@NonNull DataSnapshot dataSnapshot) {

                        String detail=dataSnapshot.child("detail").getValue().toString();

                        }

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

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

      }
    });

0 个答案:

没有答案