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