It's not current id that user logged... it's other uid from other user when other user send a request.
Asked
Active
Viewed 104 times
-3
-
https://stackoverflow.com/q/42172633/4407266 – Aditya Vyas-Lakhan Jul 06 '17 at 09:03
-
https://stackoverflow.com/a/43295289/4407266 – Aditya Vyas-Lakhan Jul 06 '17 at 09:04
-
it's impossible, right?? so request_type?? – Hoàng Vũ Khải Jul 06 '17 at 09:13
-
1Your question is getting downvoted. While I did not downvote, I can understand. I have no doubt that you're stuck and have tried to solve the problem already. But your question shows no proof of that and is not very clear to me. In such cases it helps if you post the [minimal code that reproduces where you are stuck](http://stackoverflow.com/help/mcve). At the very least that will show us what you tried, which makes it easier to help. – Frank van Puffelen Jul 06 '17 at 14:09
-
@FrankvanPuffelen tks... I will learn from this experience – Hoàng Vũ Khải Jul 08 '17 at 02:39
1 Answers
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