使用 (a)smack 检查 XMPP 中的服务器上是否存在用户 [英] Check if a user exist on server in XMPP with (a)smack

查看:40
本文介绍了使用 (a)smack 检查 XMPP 中的服务器上是否存在用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 asmack 作为库并在 android 平台上开发聊天应用程序.有什么办法可以在添加好友之前先查看服务器上是否存在该好友?

I'm working on a chat application using asmack as a library and on android platform. Is there is any way that before adding friend in Roster can I check that friend exist on server or not?

推荐答案

我找到了答案:

UserSearchManager search = new UserSearchManager(mXMPPConnection);
Form searchForm = search
    .getSearchForm("search." + mXMPPConnection.getServiceName());

Form answerForm = searchForm.createAnswerForm();
answerForm.setAnswer("Username", true);
answerForm.setAnswer("search", user);
ReportedData data = search
    .getSearchResults(answerForm, "search." + mXMPPConnection.getServiceName());

if (data.getRows() != null) {
    for (ReportedData.Row row: data.getRows()) {
        for (String value: row.getValues("jid")) {
            Log.i("Iteartor values......", " " + value);
        }
    }
    Toast.makeText(_service, "Username Exists", Toast.LENGTH_SHORT).show();
}

如果服务器没有任何指定名称的输入,则 Itearator 它没有值并且代码不会进入 while(it.hasNext)..

if Server has not any entery with that specified name then Itearator it has no value and code will not go inside while(it.hasNext)..

这篇关于使用 (a)smack 检查 XMPP 中的服务器上是否存在用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆