【问题标题】:Smack Api Group not workingSmack Api 组不工作
【发布时间】:2016-08-27 06:05:30
【问题描述】:

我正在尝试使用 Smack Api 创建组
我使用以下代码
它在muc#roomconfig_roomowners 标签上崩溃
如果我删除该行,它工作正常,组创建
但是没有分配给当前用户的组,没有人是所有者

    public void createGroup() {
        MultiUserChat chatRoom = MultiUserChatManager.getInstanceFor(mConnection).getMultiUserChat("room719@conference." + MYSITE);
        try {
            chatRoom.create("room719");
            Form form = chatRoom.getConfigurationForm().createAnswerForm();
            form.setAnswer("muc#roomconfig_publicroom", true);
            form.setAnswer("muc#roomconfig_roomname", "room719");
//            List owners = new ArrayList();
//            owners.add("currUser@"+MYSITE);
            form.setAnswer("muc#roomconfig_roomowners", Arrays.asList("currUser@"+MYSITE));
            form.setAnswer("muc#roomconfig_persistentroom", true);
            chatRoom.sendConfigurationForm(form);
        } catch (XMPPException.XMPPErrorException e) {
            e.printStackTrace();
        } catch (SmackException e) {
            e.printStackTrace();
        } catch (IllegalStateException e) {
            e.printStackTrace();
        }
    }

【问题讨论】:

  • 默认情况下,谁创建了那个人已经是所有者的组。不需要做任何额外的事情。
  • @saveen 我尝试从用户获取组功能,它没有显示任何内容,显示空数组

标签: java android xmpp smack


【解决方案1】:

这段代码对我有用,你可以试试这个吗?

 if( !chatRoom.isJoined() ){
       chatRoom.createOrJoin("your nickname");
       List<String> owners = new ArrayList<String>();
       owners.add("currUser@"+MYSITE);
       Form form = chatRoom.getConfigurationForm().createAnswerForm();
       form.setAnswer("muc#roomconfig_roomname", "your roomname");
       form.setAnswer("muc#roomconfig_roomowners", owners);
       form.setAnswer("muc#roomconfig_persistentroom", true);
       form.setAnswer("muc#roomconfig_publicroom", true);
       chatRoom.sendConfigurationForm(form);
    }

【讨论】:

    猜你喜欢
    • 2016-05-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多