SmackAndroid(上下文)找不到用户搜索模块ejabberd

时间:2017-06-10 23:35:06

标签: android chat smack ejabberd-module

我正在使用Windows上的ejabberd-17.01服务器开发基于android的聊天应用程序。使用Smack 4.1 for android。我想使用以下代码搜索用户

public void searchUser(){
    try {
        UserSearchManager userSearchManager = new UserSearchManager(connection);
        Collection<String> services = userSearchManager.getSearchServices();
        if(services.isEmpty()){
            return;
        }
        Form searchForm = userSearchManager.getSearchForm(services.iterator().next());
        Form answerForm = searchForm.createAnswerForm();
        answerForm.setAnswer("Name", true);
        answerForm.setAnswer("search", "test"); // here i'm passsing the Text value to search

        ReportedData resultData;
        resultData = userSearchManager.getSearchResults(answerForm, "search." + connection.getServiceName());

        Iterator<ReportedData.Row> it = (Iterator)resultData.getRows();
        ReportedData.Row row = null;
        while (it.hasNext()) {
            String value = it.next().toString();
            Log.i("Iteartor values......", " " + value);
            System.out.println("Jabber_id :" + row.getValues("jid").toString());
            System.out.println("Name :" + row.getValues("Name").toString());
            row = it.next();
        }
    }
    catch (SmackException.NoResponseException | SmackException.NotConnectedException | XMPPException.XMPPErrorException | XmppStringprepException e){
        Log.w("app" , e.toString());
    }
}

我的问题是 userSearchManager.getSearchServices() 返回零值。我读到关于我应该通过在连接之前调用SmackAndroid.init(上下文)初始化smack for android但是每当我写这个时它只说创建类SmackAndroid(上下文)并且不显示任何导入。

compile "org.igniterealtime.smack:smack-im:4.1.0"
compile "org.igniterealtime.smack:smack-android:4.1.0"
compile "org.igniterealtime.smack:smack-tcp:4.1.0"
compile "org.igniterealtime.smack:smack-extensions:4.1.0"

我还测试了smack文档中提到的所有依赖项,但无法找到此方法。我缺少什么,或者有没有其他方法来搜索ejabberd中的注册用户。另外我想知道我需要添加任何模块到ejabberd进行搜索,例如在openfire服务器中手动添加搜索模块吗?

0 个答案:

没有答案