0

我正在开发聊天应用程序,其中我使用的是 openfire 服务器和 asmack 库。我想搜索在该服务器上注册的用户。

这是我写的代码..

    UserSearchManager search = new UserSearchManager(connection);  
            try {
                Log.d("JWP", "cc:"+connection.getServiceName());
                org.jivesoftware.smackx.Form searchForm = search.getSearchForm("search."+connection.getServiceName());
                org.jivesoftware.smackx.Form answerForm = searchForm.createAnswerForm();  
                answerForm.setAnswer("Username", true);  
                answerForm.setAnswer("search", editTextSearch.getText().toString());  
                org.jivesoftware.smackx.ReportedData data;
                data = search.getSearchResults(answerForm,"search."+connection.getServiceName());
                if(data.getRows() != null){   
                    Iterator<org.jivesoftware.smackx.ReportedData.Row> it = data.getRows();
                    while(it.hasNext()){
                        org.jivesoftware.smackx.ReportedData.Row row = it.next();
                        Iterator iterator = row.getValues("jid");
                        if(iterator.hasNext()){
                            String value = iterator.next().toString();
                            Log.i("Iteartor values......"," "+value);
                        }
                    }
                    Toast.makeText(Welcome.this,"Username Exists",Toast.LENGTH_SHORT).show();
                }
            }
            catch (XMPPException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

但是这里的 getSerachFrom() 方法返回 null 值,尝试了各种方法但不明白为什么会这样。我的 openfire 服务器有很多注册用户。

4

0 回答 0