powered by Jive Software

Search existing Jabber Id with UserSearchManager fails

I simply want to check if a jabber id exists, if for example, a user wants to add some contacts to his list. He should check if this jabber id is valid and exists. I used UserSearchManager like seen in so many examples. I also have seen much threads here and in StackOverflow, all the poeple have problems and no “solution” works really.

I am starting the search like this:

UserSearchManager search = new UserSearchManager(mConnection);

String searchString = null;

try {

Collection services = search.getSearchServices();

String[] nn = services.toArray(new String[services.size()]);

for (int i = 0; i < nn.length; i++) {

searchString = nn[i].toString();

}

} catch (SmackException.NoResponseException e) {

e.printStackTrace();

} catch (XMPPException.XMPPErrorException e) {

e.printStackTrace();

} catch (SmackException.NotConnectedException e) {

e.printStackTrace();

}

if (searchString == null || searchString.isEmpty()) {

searchString = “search.” + mConnection.getServiceName();

}

Form searchForm = null;

try {

searchForm = search

.getSearchForm(searchString);

Form answerForm = searchForm.createAnswerForm();

answerForm.setAnswer(“user”, jabberId);

//answerForm.setAnswer(“Username”,true);

// answerForm.setAnswer(“search”, jabberId);

ReportedData data = search

.getSearchResults(answerForm, searchString);

if (data.getRows() != null) {

for (ReportedData.Row row : data.getRows()) {

for (String value : row.getValues(“jid”)) {

//get user value

}

}

}

} catch (SmackException.NoResponseException e) {

e.printStackTrace();

} catch (XMPPException.XMPPErrorException e) {

e.printStackTrace();

} catch (SmackException.NotConnectedException e) {

e.printStackTrace();

} catch (IllegalArgumentException e) {

e.printStackTrace();

}

I am able to get the answerForm with all fields, that is not the problem. I am also able to set the answer to the answerForm and can send this form. The only problem is that I get an empty ReportedData object. So, has anybody an idea why I get the emopty ReportedData? I have also tried with the answers:

answerForm.setAnswer(“Username”,true);

answerForm.setAnswer(“search”, jabberId);

But these two lines throws me an IllegalArgumentException because they don´t exist on the answer form. I have also configuered the Provide like the following:

ProviderManager.addIQProvider(“query”, “jabber:iq:search”, new UserSearch.Provider());

So did I miss something? If anybody has another solution to just check if the jabber id is valid, please show me how…many thanks for all replies.