在我的聊天应用程序中,我想实现群聊功能。同样我想创建房间并发送邀请给我的朋友加入房间。这是我的代码加入并邀请朋友到房间。
创建房间
//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");
}
});
}
为了接收邀请,我在我的服务类中实现了一个邀请监听器。但我无法通过通知收到邀请。用代码来解决问题。
这是我的邀请听众。
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");
请告诉我为什么我没有收到邀请。??
由于
答案 0 :(得分:2)
您在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();
}
}
});
它为我工作..试试吧
答案 1 :(得分:0)
你可以试试这个
public class myclass extends Activity implements InvitationListener{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MultiUserChat.addInvitationListener(Connection,myclass.this);
}
@Override
public void invitationReceived(Connection conn, final String room,
String inviter, String reason, String password, Message message) {
Log.e("inviter", inviter);
Log.e("message", message.getBody());
Log.e("reason", reason);
Log.e("room", room);
}
}
这可能会解决您的问题。
答案 2 :(得分:0)
我们错过了主题:
只需添加以下代码即可加入群组:
private void setChatRoomInvitationListener() {
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
MultiUserChat.addInvitationListener(xmppConnection, new InvitationListener() {
@Override
public void invitationReceived(Connection connection,String room, String inviter, String reason,String unKnown, Message message) {
XMPPConnectionUtils.configureChatStandards();
MultiUserChat muc = new MultiUserChat(connection, room);
try {
muc.join("My_Name_Here");
} catch (XMPPException e) {
e.printStackTrace();
}
}
});
}
});
thread.start();
}
希望这会有很大的帮助。