在我的聊天应用程序中,我想实现群聊功能。同样,我想创建房间并向我的朋友发送加入房间的邀请。这是我加入并邀请朋友进入房间的代码。
创建房间
//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, "[email protected] /cdn-cgi/l/email-protection");
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("su[email protected] /cdn-cgi/l/email-protection", "Please join this room");
}
});
}
为了接收邀请,我在我的服务类中实现了一个邀请侦听器。但我无法通过通知收到邀请。代码有问题。
这是我的邀请听众。
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");
请告诉我为什么我没有收到邀请。?
Thanks
你写这段代码之后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();
}
}
});
它对我有用..试试吧
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)