【发布时间】:2020-12-04 22:27:00
【问题描述】:
当我打开特定群组的聊天窗口时,我通过以下代码创建/加入群组
private MultiUserChat joinRoom(String roomName) throws XmppStringprepException, XMPPException.XMPPErrorException, MultiUserChatException.NotAMucServiceException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException, MultiUserChatException.MucAlreadyJoinedException {
if (roomName.equals("")) {
logAndToast("Enter room name");
return null;
}
if (MyXMPP.connection != null && MyXMPP.connection.isAuthenticated()) {
// Get the MultiUserChatManager
MultiUserChatManager manager = MultiUserChatManager.getInstanceFor(MyXMPP.connection);
// Create the XMPP address (JID) of the MUC.
EntityBareJid mucJid = (EntityBareJid) JidCreate.bareFrom(XMPPHelper.getRoomName(roomName));
// Create a MultiUserChat using an XMPPConnection for a room
MultiUserChat muc2 = manager.getMultiUserChat(mucJid);
// User2 joins the new room
// The room service will decide the amount of history to send
// Create the nickname.
Resourcepart nickname = Resourcepart.from(PreferenceManager.getStringPreference(this, PreferenceManager.XMPP_USER_NAME));
MucEnterConfiguration.Builder mec = muc2.getEnterConfigurationBuilder(nickname);
MucEnterConfiguration mucEnterConfig = mec.build();
muc2.join(mucEnterConfig);
return muc2;
}
return null;
}//end of MultiUserChat()
之后,我为组设置传入消息侦听器,如下所示
multiUserChat = joinRoom("myRoomName"));
if (multiUserChat != null) {
multiUserChat.addMessageListener(new MessageListener() {
@Override
public void processMessage(final Message message) {
//here I received messages for the perticular group that I joined
}
});
if (multiUserChat.isJoined()) {
logAndToast("join xmpp room successfully");
} else {
logAndToast("join xmpp room not joined");
}
}
当我在特定的组窗口中时,我收到了上述代码的所有消息。
我需要一个解决方案,当我在组窗口之外时如何接收所有组中的所有传入消息。
我在下面提到了 MUC 群聊的链接 https://download.igniterealtime.org/smack/docs/latest/documentation/extensions/muc.html
我搜索/访问了许多链接,但找不到任何对我有用的解决方案。请帮我提供一个解决方案。
提前致谢。
【问题讨论】:
-
您好,感谢您提出的好问题。我实际上正在寻找相同的方法,您是否设法得到解决方案。?
-
是的,我们可以在单独的地方获取所有群消息,我们需要订阅群
标签: android smack multiuserchat