Smack Api Group无法正常工作

时间:2016-08-27 06:05:31

标签: java android xmpp smack

我正在尝试使用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();
        }
    }

1 个答案:

答案 0 :(得分:0)

这段代码对我有用,你能试试吗?

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