0

I have received data from an XMPP server, as a result of a search(IQ). The whole story is related here. This is the code:

UserSearchManager usm = new UserSearchManager(ChatList.connection);
                    Form searchForm = null;
                    try {
                    searchForm = usm.getSearchForm("search.webserv.xxx.com");
                    } catch (XMPPException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    Form answerForm = searchForm.createAnswerForm();
                    answerForm.setAnswer("Username", true);
                    answerForm.setAnswer("search", "android");

                    try {
                     ReportedData data = 
                     usm.getSearchResults(answerForm, "search.webserv.xxx.com");
                    } catch (XMPPException e) {
                        e.printStackTrace();
                    }

So the results are contained within the "data" variable, but I don't know how to access it. There are almost no answeres out there on google, I've been at this problem (and the whole xmpp thing) for a while now. Can a wiser man than me please tell me how to search and add someone to my xmpp chat contact list?

Community
  • 1
  • 1
Sebek
  • 642
  • 8
  • 22
  • 1
    I would check out the javadoc for ReportedData (http://www.igniterealtime.org/builds/smack/docs/latest/javadoc/org/jivesoftware/smackx/ReportedData.html). It looks like you can iterate over the columns, get the variable you need, then iterate over the rows using the variable to extract the data. – brimil01 Nov 16 '12 at 16:14

1 Answers1

0

https://stackoverflow.com/a/14214622/1688731

Here is the code:

UserSearchManager search = new UserSearchManager(mXMPPConnection);  

        Form searchForm = search.getSearchForm("search."+mXMPPConnection.getServiceName());

        Form answerForm = searchForm.createAnswerForm();  
        answerForm.setAnswer("Username", true);  

        answerForm.setAnswer("search", user);  

        org.jivesoftware.smackx.ReportedData data = search.getSearchResults(answerForm,"search."+mXMPPConnection.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);
            }
             Toast.makeText(_service,"Username Exists",Toast.LENGTH_SHORT).show();
             );
        }
Community
  • 1
  • 1
Sebek
  • 642
  • 8
  • 22