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?
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)..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With