gpt4 book ai didi

android - XMPP 房间邀请

转载 作者:行者123 更新时间:2023-11-29 00:35:14 27 4
gpt4 key购买 nike

在我的聊天应用程序中,我想实现群聊功能。同样,我想创建房间并将邀请发送给我的 friend 加入房间。这是我加入并邀请 friend 加入房间的代码。

创建房间

//Create Room
btn_CreateRoom = (Button)findViewById(R.id.btn_usermenu_CreateRoom);
btn_CreateRoom.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub

try {
muc = new MultiUserChat(connection, "room1@conference.abc.com");

muc.join("Sunil","123456");
muc.sendConfigurationForm(new Form(Form.TYPE_SUBMIT));

} catch (XMPPException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

System.out.println("Room Created");
}
});


btn_Invite = (Button)findViewById(R.id.btn_usermenu_InviteToRoom);
btn_Invite.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub


muc.invite("sunil@abc.com", "Please join this room");



}
});

}

为了接收邀请,我在我的服务类中实现了一个邀请监听器。但是我无法通过通知收到邀请。 Wats 代码的问题。

这是我的邀请监听器。

MultiUserChat.addInvitationListener(connection, new InvitationListener() {

@Override
public void invitationReceived(Connection arg0, String arg1, String arg2,
String arg3, String arg4, Message arg5) {
// TODO Auto-generated method stub

System.out.println("Received??");
notification("Invitation Received");

请告诉我为什么我没有收到邀请。??

谢谢

最佳答案

你在 xmppconnection.connect() 之后写这段代码

MultiUserChatManager.getInstanceFor(connection).addInvitationListener(new InvitationListener() {
@Override
public void invitationReceived(XMPPConnection conn, MultiUserChat room, String inviter, String reason, String password, Message message) {
MultiUserChatManager manager = MultiUserChatManager.getInstanceFor(conn);
try {
room.join("pandian");
} catch (SmackException.NoResponseException e) {
e.printStackTrace();
} catch (XMPPException.XMPPErrorException e) {
e.printStackTrace();
} catch (SmackException.NotConnectedException e) {
e.printStackTrace();
}
}


});

它对我有用..尝试一下

关于android - XMPP 房间邀请,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13028384/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com