0

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

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

所以结果包含在“数据”变量中,但我不知道如何访问它。google 上几乎没有答案,我已经解决这个问题(以及整个 xmpp 问题)有一段时间了。比我更聪明的人可以告诉我如何搜索并将某人添加到我的 xmpp 聊天联系人列表中吗?

4

1 回答 1

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();
             );
        }
于 2013-02-08T13:00:48.137 回答