使用来自XMPP通信的ReportedData

时间:2012-11-16 15:27:22

标签: android search xmpp communication

作为搜索(IQ)的结果,我收到了来自XMPP服务器的数据。整个故事都与here有关。这是代码:

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

因此结果包含在“data”变量中,但我不知道如何访问它。谷歌几乎没有回答,我一直在这个问题(和整个xmpp的事情)一段时间了。能比我更聪明的人请告诉我如何搜索并添加某人到我的xmpp聊天联系人列表中?

1 个答案:

答案 0 :(得分:0)

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

以下是代码:

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