如何在MUC中接受邀请?

时间:2018-09-19 12:34:52

标签: android xmpp smack multiuserchat

我正在使用xmpp开发聊天应用程序。我已经使用MUC创建了群组,并向其他用户发送了邀请。但是我不知道如何接受和拒绝邀请。

这是我发送邀请的代码:

 EntityBareJid userInviteJID = JidCreate.entityBareFrom("user2@servicename");
 muc2.invite(userInviteJID, "Meet me in this excellent room");

我已经在InvitationReceived()方法中尝试了MultiUserChat.decline(conn, room, inviter.asBareJid()s, "I'm busy right now");方法。但是问题是MultiUserChat.decline()方法给出了错误:

  

无法解析方法拒绝()

有人可以帮助我吗?

2 个答案:

答案 0 :(得分:0)

我找到了拒绝邀请的答案。

此功能已移至MultiUserChatManager,它与MultiUserChat的特定实例无关,因此它是静态的,现在是管理器的功能。

MultiUserChatManager.getInstanceFor(connection).decline(roomJID,inviter.asEntityBareJid(),"reason");

但是接受邀请该怎么办?任何人都可以回答我吗?

答案 1 :(得分:0)

您需要在获得邀请时自动加入,这是建立连接后的代码。

 MultiUserChatManager.getInstanceFor(MyApplication.connection).addInvitationListener(new InvitationListener() {
        @Override
        public void invitationReceived(XMPPConnection conn, MultiUserChat room, EntityJid inviter, String reason, String password, Message message, MUCUser.Invite invitation) {
            //  Log.e(TAG, "invitationReceived() called with: conn = [" + conn + "], room = [" + room + "], inviter = [" + inviter + "], reason = [" + reason + "], password = [" + password + "], message = [" + message + "], invitation = [" + invitation + "]");
            LogM.e("invitationReceived() called with: conn = [" + conn + "], room = [" + room + "], inviter = [" + inviter + "], reason = [" + reason + "], password = [" + password + "], message = [" + message + "], invitation = [" + invitation + "]");

            try {
                Resourcepart nickname = null;
                try {
                    nickname = Resourcepart.from("MY_JID_HERE");
                } catch (XmppStringprepException e) {
                    e.printStackTrace();
                }

                try {

                    room.join(nickname); //while get invitation you need to join that room
                    room.getRoom().getLocalpart();
                } catch (SmackException.NoResponseException e) {
                    e.printStackTrace();
                } catch (SmackException.NotConnectedException e) {
                    e.printStackTrace();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } catch (MultiUserChatException.NotAMucServiceException e) {
                    e.printStackTrace();
                }

                Log.e(TAG, "join room successfully");

            } catch (XMPPException e) {
                e.printStackTrace();
                Log.e(TAG, "join room failed!");
            }

        }
    });