我怎样才能在Asmack获得ChatRoom会员列表?

时间:2014-08-05 10:05:10

标签: android openfire asmack

我正在使用Asmack4.0来开火,我可以登录,注册用户但我也希望从创建的聊天室获取用户列表,我正在使用此代码

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

但我的Iterator<String> it大小总是为零,请纠正我在哪里犯错误?谢谢。

1 个答案:

答案 0 :(得分:-1)

如果您没有加入MUC,则无法获得当前居住者。

使用

muc.createOrJoin(String);

创建或加入MCU。