简体   繁体   English

从Android中的Openfire Server获取所有用户的列表

[英]Get List of all users from Openfire Server in Android

Hello i am developing a chat app in android using xmpp and open-fire for server, 您好我正在使用xmpp开发一个聊天应用程序,并在服务器上使用open-fire,

currently i can create new user and login with that user. 目前我可以创建新用户并使用该用户登录。

i have searched a lot of on net and tried different solutions but nothing is worked. 我在网上搜索了很多,并尝试了不同的解决方案,但没有任何工作。

at server all users are automatically get added to one default group. 在服务器上,所有用户都会自动添加到一个默认组中。 when new user get created. 当新用户被创建时。

but i am unable to get list of all users until i will add them to my roster. 但我无法获得所有用户的列表,直到我将它们添加到我的名册。

my requirement is to show all user's list and allow user to add friend from them, how to get all users list those who are not my friend? 我的要求是显示所有用户的列表,并允许用户添加他们的朋友,如何让所有用户列出那些不是我朋友的人?

i have tried to get list of users from group, but still no success, i can only retrieve list of users those are my friends with following code. 我试图从组中获取用户列表,但仍然没有成功,我只能通过以下代码检索那些是我的朋友的用户列表。

Roster roster = xmppConnection.getRoster();
        Collection<RosterEntry> entries = roster.getEntries();

            for(RosterEntry entry1 : entries)
            {
                System.out.println("UserID:- " + entry1.getUser());
                System.out.println("Name:- " + entry1.getName());
                System.out.println("Status:- " + entry1.getStatus());
                System.out.println("type:- " + entry1.getType());   
            }

to retrieve user entry from group i used following code 从我使用以下代码的组中检索用户条目

    Roster roster = xmppConnection.getRoster();
    Collection<RosterGroup> groups = roster.getGroups();
    for(RosterGroup group: groups )
            {
                System.out.println("Group Name:- " + group.getName());
            Collection<RosterEntry> entries = roster.getEntries();

            for(RosterEntry entry1 : entries)
            {
                System.out.println("UserID:- " + entry1.getUser());
                System.out.println("Name:- " + entry1.getName());
                System.out.println("Status:- " + entry1.getStatus());
                System.out.println("type:- " + entry1.getType());   
            }   
        }

any help/solution or suggestion to get all users list is appreciated. 任何帮助/解决方案或建议,以获得所有用户列表表示赞赏。

Thank you. 谢谢。

following code is working for me : 以下代码对我有用:

UserSearchManager usm = new UserSearchManager(connection);

Form searchForm = usm.getSearchForm("search." + connection.getServiceName());
//Here i am searching for the service name

Form answerForm = searchForm.createAnswerForm();

UserSearch userSearch = new UserSearch();
answerForm.setAnswer("Username", true);

answerForm.setAnswer("search", "*");

ReportedData data = userSearch.sendSearchForm(connection, answerForm, "search." + connection.getServiceName());

if (data.getRows() != null) {
    System.out.println("not null");

    Iterator<ReportedData.Row> it = data.getRows();

    arryAllUsers.clear();

    while (it.hasNext()) {

        //System.out.println("row");

        ReportedData.Row row = it.next();

        Iterator iterator = row.getValues("jid");

        if (iterator.hasNext()) {

            String jid = iterator.next().toString(); //here i get all the user's of the open fire..
            // l.add(value);

        }

        // Log.i("Iteartor values......"," "+value);

    }
}

I can suggest the following: 我可以建议如下:

  1. setup "shared roster" on the server, take a look at https://community.igniterealtime.org/docs/DOC-1619 - every user will have all server users in the roster. 在服务器上设置“共享名册”,看看https://community.igniterealtime.org/docs/DOC-1619 - 每个用户都将拥有名册中的所有服务器用户。
  2. when user mark someone as "friend" - add that user to some group, eg "Friends". 当用户将某人标记为“朋友”时 - 将该用户添加到某个组,例如“朋友”。 And display that group as user's roster. 并将该组显示为用户的名单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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