Home > DeveloperSection > Forums > Get List of all users from Openfire Server in Android
zack mathews
zack mathews

Total Post:23

Points:161
Posted on    December-10-2015 4:48 AM

 Android Android  Android Listview 
Ratings:


 1 Reply(s)
 359  View(s)
Rate this:
Hello i am developing a chat app in android using xmpp and open-fire for server, 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.


Mayank Tripathi
Mayank Tripathi

Total Post:397

Points:3117
Supported
Posted on    December-10-2015 4:56 AM

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.
When user mark someone as "friend" - add that user to some group, e.g. "Friends". And display that group as user's roster.

Following code works 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);
    }
}

Don't want to miss updates? Please click the below button!

Follow MindStick