我可以添加组,但它显示“房间被锁定,直到配置被确认”。我进行了研究,但没有找到任何令人满意的答案。下面是它如何获取 XMPP 连接并提交表单的代码。并在发送表单时抛出“未授权异常”。
xmppConnection = connectionThread.getXMPPConnection();
if (xmppConnection == null) {
Application.getInstance().onError(R.string.NOT_CONNECTED);
return;
}
final MultiUserChat multiUserChat;
try {
multiUserChat = new MultiUserChat(xmppConnection, room);
// setConfig(multiUserChat);
} catch (IllegalStateException e) {
Application.getInstance().onError(R.string.NOT_CONNECTED);
return;
}
//提交表单的代码。
private void setConfig(MultiUserChat multiUserChat) {
try {
Form form = multiUserChat.getConfigurationForm();
Form submitForm = form.createAnswerForm();
for (Iterator<FormField> fields = submitForm.getFields(); fields
.hasNext();) {
FormField field = (FormField) fields.next();
if (!FormField.TYPE_HIDDEN.equals(field.getType())
&& field.getVariable() != null) {
submitForm.setDefaultAnswer(field.getVariable());
}
}
submitForm.setAnswer("muc#roomconfig_publicroom", true);
submitForm.setAnswer("muc#roomconfig_persistentroom", true);
multiUserChat.sendConfigurationForm(submitForm);
} catch (Exception e) {
e.printStackTrace();
}
}