XMPP Room Invitation

我只是一个虾纸丫 提交于 2019-12-04 15:12:21

you write this code after 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();
                        }
                    }


                });

its work for me ..try it

You can try this

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);

    }
}

This might solve your problem.

We missed Thread here:

Just add below code to join group:

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();
    }

Hope this will help a lot.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!