简体   繁体   English

如何使用smack Api向XMPP服务器发送和接收朋友请求

[英]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); 如何使用SMACK API在Android中发送和接收朋友请求。我知道将用户添加到名册中,我可以使用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. 希望这会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Android 中使用 XMPP 服务器发送/接收好友请求 - Send/receive friend request using XMPP server in Android android如何使用xmpp-smack在群聊中发送和接收图像和位置(使用地图) - android how to send and receive image and location (using map ) in group chat using xmpp-smack 如何接收消息而不使用createChat for android XMPP chat smack api - How to receive message without using createChat for android XMPP chat smack api XMPP(与smack) - 添加好友 - XMPP ( with smack) - Adding Friend 如何在Android中使用Parse以编程方式发送和接收朋友请求 - How to Send and receive Friend Request Programmatically in android using Parse 如何使用Android中的asmack库发送和接收朋友请求? - How to send and receive friend request using asmack library in android? 使用您自己的XMPP服务器为Android聊天应用程序(Smack API) - Using your own XMPP server for android chat app (Smack API) 使用Android上的Smack API连接到localhost上的ejabberd XMPP服务器 - Connecting to a ejabberd XMPP server on localhost using Smack API on android 如何在聊天中使用smack通过xmpp发送联系人? - how to send contacts over xmpp using smack in a chat? 如何使用Smack将XMPP消息从Android发送到GAE - How to send a XMPP message from Android to GAE using Smack
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM