How to Display The Current Logged In User Firebase

后端 未结 1 1054
终归单人心
终归单人心 2021-01-02 17:13
    mAuth = FirebaseAuth.getInstance();
    mFirebaseDatabase = FirebaseDatabase.getInstance();
    myRef = mFirebaseDatabase.getReference().child(\"Users\");
    Fi         


        
1条回答
  •  囚心锁ツ
    2021-01-02 17:54

    First get uid of the current user that is logged in:

    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
    String userid = user.getUid();
    

    then retrieve the data of the current user:

    DatabaseReference ref = FirebaseDatabase.getInstance().getReference("Users");
    ref.child(userid).addListenerForSingleValueEvent(new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) { 
    String name = dataSnapshot.child("name").getValue().toString(); 
    name1.setText(name);
    }
    

    Assuming you have this:

    Users
      userid
         name: peter
         //etc
    

    0 讨论(0)
提交回复
热议问题