【问题标题】:How to accept invitation in MUC?如何在纽约接受邀请?
【发布时间】:2018-09-19 12:34:51
【问题描述】:

我正在使用 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() 方法给出错误:

无法解析方法deploy()

谁能帮帮我?

【问题讨论】:

    标签: android xmpp smack multiuserchat


    【解决方案1】:

    您需要在收到邀请时自动加入,这是连接完成时的代码。

     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!");
                }
    
            }
        });
    

    【讨论】:

      【解决方案2】:

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

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

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

      但是如何接受邀请呢?谁能回答我好吗?

      【讨论】:

      • 您需要编辑您的问题而不是给出答案。
      猜你喜欢
      • 1970-01-01
      • 2018-06-18
      • 1970-01-01
      • 1970-01-01
      • 2013-09-19
      • 2013-01-17
      • 1970-01-01
      • 1970-01-01
      • 2018-10-03
      相关资源
      最近更新 更多