0

I am using openfire server for my android application. I want to get all the registered user from the server to my android app. I am using xmpp asmack library.

This is the code I am trying on

UserSearchManager search = new UserSearchManager(connection);

        Form searchForm,answerForm;
        try {
            searchForm = search.getSearchForm("search."+connection.getServiceName());
            answerForm = searchForm.createAnswerForm();  
            answerForm.setAnswer("Username", true);  

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

            org.jivesoftware.smackx.ReportedData data;

            data = search.getSearchResults(answerForm,"search."+connection.getServiceName());
            if(data.getRows() != null)
            {
                Iterator<Row> it = data.getRows();
                while(it.hasNext())
                {
                    Row row = it.next();
                    Iterator iterator = row.getValues("jid");
                    if(iterator.hasNext())
                    {
                        String value = iterator.next().toString();
                        Log.i("Iteartor values......"," "+value);
                    }
                    //Log.i("Iteartor values......"," "+value);
                }

            }
    } catch (XMPPException e2) {
            // TODO Auto-generated catch block
            e2.printStackTrace();
        }

Please suggest any method

  • 1
    and i want 1 million ... what have you tried? – Selvin May 28 '14 at 10:21
  • i am not getting any code – user2718007 May 28 '14 at 10:25
  • because you have to write it on your own ... Stackoverflow is not "write the code for me" service – Selvin May 28 '14 at 10:25
  • [This question](http://stackoverflow.com/questions/20279558/ios-xmpp-framework-with-openfire-server-get-all-registered-users) has examples of how to do it in Objective C. It should be fairly easy to translate them to Java and aSmack. – legoscia May 28 '14 at 10:45

1 Answers1

2

Somehow I figured out the answer

public List getAllUser(){

List<String> l = new ArrayList<String>();

UserSearchManager search = new UserSearchManager(connection);
try {
    Form searchForm = search.getSearchForm("search." + connection.getServiceName());
    Form answerForm = searchForm.createAnswerForm();

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

    System.out.println("search form");
    ReportedData data = search.getSearchResults(answerForm, "search."+connection.getHost());



    if(data.getRows() != null)
        {
        System.out.println("not null");
            Iterator<Row> it = data.getRows();
            while(it.hasNext())
            {
                //System.out.println("row");
                Row row = it.next();
                Iterator iterator = row.getValues("jid");
                if(iterator.hasNext())
                {
                String value = iterator.next().toString();
                l.add(value);
               // Log.i("Iteartor values......"," "+value);
                }
                //Log.i("Iteartor values......"," "+value);
            }

        }else{
            System.out.println("its null");
        }
} catch (XMPPException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
    System.out.println("not search form");
}
return l;

}

List l = new ArrayList();

    l = con.getAllUser();


    for(int i=0;i<l.size();i++)
        System.out.println(l.get(i));
  • @RishabhSrivastava check if the connection has been established with the xmpp server ........ – user2718007 Oct 16 '14 at 11:35
  • can you post the error @RishabhSrivastava – user2718007 Oct 17 '14 at 10:23
  • You need to provide provider manager code. working solution is here:http://stackoverflow.com/questions/8213812/search-for-existing-user-using-xmpp-usersearchmanager-in-android/27597429#27597429 – shyam.y Dec 22 '14 at 09:31