简体   繁体   中英

How to send and receive friend request to XMPP server using smack Api

How to send and receive friend request in android using SMACK API.I know to add user to roster i can use roster.createEntry("abcd@203.xxx.xx.xx", "abcd", null); but i want to ask to user if he/she wants to add me to their roster or not.How to achieve this?

Instead of creating a Roster, just send him/her a presence, with the subscribe type, then when he/she receives the subscribe presence, you show the Accept/Decline dialog. If he/she accepts, then he/she sends back a subscribed type presence and also a subscribe type presence and creates a roster(it is needed to set the rosters name). Now the user who initially sent the subscribe, receives a subscribed and a subscribe type presence from the user he/she added as a friend. Receiving these, he/she sends back automatically a subscribed type presence and creates a roster.

Simpler way:

User1 ----subscribe---> User2

show dialog
if accept
User2 ----subscribed---> User1
User2 ----subscribe---> User1
create roster with name(which is actually modifying the roster, since the subscribe creates one, without a name)

without dialog
User1 ----subscribed---> User2
create roster with name(which is actually modifying the roster, since the subscribe creates one, without a name)
end if

else
User2 ----unsubscribed---> User1
User1 delete roster
end else

Hope this helped.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM