Check if a user exist on server in XMPP with (a)smack

你。 提交于 2019-12-07 02:51:47

问题


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?


回答1:


I Found the answer :

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

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)..



来源:https://stackoverflow.com/questions/14209294/check-if-a-user-exist-on-server-in-xmpp-with-asmack

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!