-1

I am Using Asmack4.0 to work with open fire and I am able to login, register user but I also want to get user list from created chat-room, I am Using this code

Collection<HostedRoom> rooms = null;
    try {
        ServiceDiscoveryManager discoManager = new ServiceDiscoveryManager(XMPPChatDemoActivity.connection);
        rooms = MultiUserChat.getHostedRooms(XMPPChatDemoActivity.connection, "conference.centos65");

        Log.e("", "" + rooms.size());
        for (HostedRoom room : rooms) {
            Log.e("", "" + room.getName());
            MultiUserChat muc = new MultiUserChat(XMPPChatDemoActivity.connection, room.getJid());

            ArrayList<String> tempArrayList = new ArrayList<String>();
            tempArrayList = findMulitUser(muc);

            listDataChild.put(room.getName(), tempArrayList);

        }

    } catch (Exception e) {
        e.printStackTrace();
    }

public static ArrayList<String> findMulitUser(MultiUserChat muc) {

    ArrayList<String> listUser = new ArrayList<String>();

    Iterator<String> it = muc.getOccupants();

    // size of `it` getting always zero

    while (it.hasNext()) {
        String name = StringUtils.parseResource(it.next());
        listUser.add(name);
        Log.e("", "" + name);
    }
    return listUser;
}

But I am getting size of Iterator<String> it always zero, please correct me where I am doing mistake ? Thank you.

Jignesh Ansodariya
  • 12,583
  • 24
  • 81
  • 113

1 Answers1

-1

You can't get the current occupants if you didn't join the MUC.

Use

muc.createOrJoin(String);

to create or join the MCU.

Flow
  • 23,572
  • 15
  • 99
  • 156