使用Smack从Openfire服务器获取聊天室列表

时间:2014-12-08 08:25:21

标签: java android chat openfire asmack

任何机构都知道如何使用Asmack库从openfireServer获取聊天室列表。帮助我。

谢谢

3 个答案:

答案 0 :(得分:2)

使用此选项获取用户已加入的房间名称列表:

Iterator roomsJoinedByUser = MultiUserChat.getJoinedRooms(connection, "abc@abc.com");

使用此列表获取所有托管房间的列表:

Collection<HostedRoom> rooms = MultiUserChat.getHostedRooms(connection, "service_name");

答案 1 :(得分:1)

这是我的代码希望它有所帮助

&#13;
&#13;
  Collection<HostedRoom> rooms = MultiUserChat.getHostedRooms(connection, "conference.nubes-pc-1");

            if (!rooms.isEmpty()){
                for (HostedRoom room : rooms) {
                    Log.d("yo", room.getName()+" "+ room.getJid());
                }
            }
&#13;
&#13;
&#13;

答案 2 :(得分:0)

如您所见,MultiUserChat。 getHostedRooms 可以帮助您:

public static List<HostedRoom>  getHostRooms(XMPPConnection xmppConnection){
    List<HostedRoom> roominfos = new ArrayList<HostedRoom>();
    try {
        new ServiceDiscoveryManager(xmppConnection);
        Collection<HostedRoom> hostrooms = 
MultiUserChat.getHostedRooms(xmppConnection,xmppConnection.getServiceName());
        for (HostedRoom entry : hostrooms) {
            roominfos.add(entry);
            Log.i("room", "name:" + entry.getName() + " - ID:" + entry.getJid());
        }
        Log.i("room", "number:" + roominfos.size());
    } catch (XMPPException e) {
        Log.e("getHostRooms",e.getMessage());
        e.printStackTrace();
    }
    return roominfos;
}