我正在使用MUC进行群聊,使用smack。我想获得用户已经参与的MUC房间列表,如whatsapp。
使用belove代码,我只获得用户加入的房间,但我需要获得我已经成为其成员的所有组。
这是我的代码:
List<EntityBareJid> joinedRoomes = manager.getJoinedRooms(conn);
for (EntityBareJid jRoomName : joinedRoomes) {
Log.e("Group Chat : Joined room = " , jRoomName.toString());
}
有人帮帮我吗?
另外,我想为MUC组添加头像图像。我怎样才能做到这一点?
没有命令获取帐户是成员/管理员/所有者的房间列表...只有一个命令来获取特定房间的从属关系列表。
另外,我想为MUC组添加头像图像。我怎样才能做到这一点?
房间没有vcard,因此无法存储图像。但它有一个“描述”字段,您可以在其中放置头像图像的URL,然后修改客户端以读取该URL并将图像显示为房间头像。
您可以尝试这种方式来获取组成员和详细信息
public static List<String> getRoomInfo(String grp_id) {
List<String> jids = new ArrayList<>();
try {
EntityBareJid mucJid = JidCreate.entityBareFrom(grp_id + "@" + Constants.GRP_SERVICE);
mucChatManager = MultiUserChatManager.getInstanceFor(MyApplication.connection);
mucChat = mucChatManager.getMultiUserChat(mucJid);
RoomInfo info = mucChatManager.getRoomInfo(mucJid);
LogM.e("Number of occupants:" + info.getOccupantsCount());
LogM.e("Room Subject:" + info.getSubject());
Log.e(TAG, "members " + mucChat.getMembers().size());
List<Affiliate> affiliatesMembers = mucChat.getMembers();
Log.e(TAG, "members1 " + affiliatesMembers.size());
for (Affiliate affiliate : affiliatesMembers) {
Log.e(TAG, "members: Jid:" + affiliate.getJid()
);
if (affiliate.getJid() != null) {
jids.add(affiliate.getJid().toString());
}
}
return jids;
} catch (SmackException.NoResponseException | XMPPException.XMPPErrorException | InterruptedException | XmppStringprepException e) {
Log.e(TAG, "Group Error : " + e.getMessage());
} catch (SmackException.NotConnectedException e) {
Log.e(TAG, "Group Error2 : " + e.getMessage());
}
return jids;
}