简体   繁体   中英

Get the Chat Room List from the Openfire Sever USING Asmack

Any body know how to get the chat room list from openfireServer using Asmack library .Help me .

Thanks

Use this to get list of room names that the user has joined:

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

Use this to get list all hosted rooms:

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

here is my code hope it helps

  Collection<HostedRoom> rooms = MultiUserChat.getHostedRooms(connection, "conference.nubes-pc-1"); if (!rooms.isEmpty()){ for (HostedRoom room : rooms) { Log.d("yo", room.getName()+" "+ room.getJid()); } } 

As you see, MultiUserChat. getHostedRooms can help you:

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM