-3

It's not current id that user logged... it's other uid from other user when other user send a request.

How can I take this uid.

KENdi
  • 7,576
  • 2
  • 16
  • 31

1 Answers1

1

From what I understand, you want to get to know whenever you receive a friend request. I see that you've created a Friend_req node and have each user's keys inside it. This is good. I assume that you do have a minimal grasp of Firebase and flattening of data.

With this assumption, my answer is that you need a childEventListener on the node that you need to track for friend requests. The childEventListener has a onChildAdded() method that downloads data whenever a new child is added to the code ( in your case, a new friend request ). Here's a basic implementation.

FirebaseDatabase.getInstance().getReference().child("Friend_req")
    .child(yourUserKey).addChildEventListener(new ChildEventListener() {

public void onChildAdded(DataSnapshot dataSnapshot, String s) {
//Get notified on friend request
}

 @Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
}

@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {

                                            }

@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {

                                            }

@Override
public void onCancelled(DatabaseError databaseError) {

}
});
Rohan Stark
  • 2,346
  • 9
  • 16