使用来自 XMPP 通信的报告数据



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

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 聊天联系人列表中吗?

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

相关内容

  • 没有找到相关文章

最新更新