我正在开发聊天应用程序。我做了一对一的聊天。但我无法创建群聊,因为它显示以下错误
'MultiUserChat(org.jivesoftware.smack.XMPPConnection, org.jxmpp.jid.EntityBareJid, org.jivesoftware.smackx.muc.MultiUserChatManager)' is not public in 'org.jivesoftware.smackx.muc.MultiUserChat'.
Cannot be accessed from outside package
我已经看到了一些关于使用multiUserChat = new MultiUserChat(connection,room_name);
创建群组来创建群组的答案。
但是在4.2.0-beta1版本中不允许我们访问此类。
我在
下添加了我的代码 public void createGroupChat() {
// Create a MultiUserChat using a Connection for a room
// (room name as the second parameter)
try {
Resourcepart nikname = Resourcepart.from("admin");
MultiUserChat mMultiUserChat = new MultiUserChat(connection, "room@conference.myserver");
mMultiUserChat.create(nikname);
Form form = mMultiUserChat.getConfigurationForm().createAnswerForm();
form.setAnswer("muc#roomconfig_publicroom", true);
form.setAnswer("muc#roomconfig_roomname", "room");
form.setAnswer("muc#roomconfig_roomowners", "owner");
form.setAnswer("muc#roomconfig_persistentroom", true);
mMultiUserChat.sendConfigurationForm(form);
} catch (XmppStringprepException e) {
e.printStackTrace();
} catch (MultiUserChatException.MucAlreadyJoinedException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (XMPPException.XMPPErrorException e) {
e.printStackTrace();
} catch (MultiUserChatException.MissingMucCreationAcknowledgeException e) {
e.printStackTrace();
} catch (NotConnectedException e) {
e.printStackTrace();
} catch (SmackException.NoResponseException e) {
e.printStackTrace();
} catch (MultiUserChatException.NotAMucServiceException e) {
e.printStackTrace();
}
}
有谁能告诉我如何在最新的smack 4.2.0-beta1版本中创建组?
如果我对此有任何不妥之处。
答案 0 :(得分:0)
我找到了通过以下链接创建群聊的答案
https://github.com/igniterealtime/Smack/blob/master/documentation/extensions/muc.md
我也添加了新代码。它对其他一些开发人员有帮助
public void createGroupChat() {
// Create a MultiUserChat using a Connection for a room
// Get the MultiUserChatManager
MultiUserChatManager manager = MultiUserChatManager.getInstanceFor(connection);
try {
EntityBareJid jid = JidCreate.entityBareFrom("myroom" + "@"
+ context.getString(R.string.serviceNameOld));
// Create a MultiUserChat using an XMPPConnection for a room
MultiUserChat muc = manager.getMultiUserChat(jid);
// Prepare a list of owners of the new room
Set<Jid> owners = JidUtil.jidSetFrom(new String[]{"mathan@example.org", "kumar@example.org"});
// Create the room
Resourcepart nickname = Resourcepart.from("mathan");
muc.create(nickname).getConfigFormManager().setRoomOwners(owners).submitConfigurationForm();
} catch (XmppStringprepException e) {
e.printStackTrace();
} catch (MultiUserChatException.MucAlreadyJoinedException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (XMPPException.XMPPErrorException e) {
e.printStackTrace();
} catch (MultiUserChatException.MissingMucCreationAcknowledgeException e) {
e.printStackTrace();
} catch (NotConnectedException e) {
e.printStackTrace();
} catch (SmackException.NoResponseException e) {
e.printStackTrace();
} catch (MultiUserChatException.NotAMucServiceException e) {
e.printStackTrace();
} catch (MultiUserChatException.MucConfigurationNotSupportedException e) {
e.printStackTrace();
}
}