How to get openfire registered users from android client using aSmack

Hi All,

i am trying to create chat app.

  • I installed openfire server in my local machine

  • And added some users through openfire server admin panel

  • Now i am trying to display all available users in android Emulator. iam using android 4 and asmack-android-19-0.8.10.jar

  • I am able to connected to openfire server usign aSmack lib. But not possible to fetch all avaialble users using Roster.

My code sample using in AsyncTask doInBackground method :

ConnectionConfiguration config = new ConnectionConfiguration(“”, 5222, “localhost”);

connection = new XMPPConnection(config);

try {


Log.d("SMACK “, " CONNECTED”);

// list online contacts

Roster roster = connection.getRoster();

Collection entries = roster.getEntries();

Log.d(“TRACE”, “entries.size()=” + entries.size());

for (RosterEntry e : entries) {

Log.d(“PRESENCE”, e.getUser() + “=” + roster.getPresence(e.getUser()).isAvailable());

if (roster.getPresence(e.getUser()).isAvailable()) {

Log.d(“ADD”, “NAME_KEY=” + e.getName() + " USERJID_KEY=" + e.getUser());





catch (XMPPException e){

Log.e(“XMPPChatDemoActivity”, "Failed to connect to "+ connection.getHost());

Log.e(“XMPPChatDemoActivity”, e.toString());


This code always gives “entries.size()” is ZERO.

Please suggest me how can i get registered users?

And how to registered users to openserver through Android client?

I explored internet from few days. But i did not get LUCK.

Please help me…

Thanks in advance…

I see no login in your code. You need to login first (authenticate your connection) because each user account has its own roaster
from smack documentation: Rosters and presence use a permissions-based model where users must give permission before they are added to someone else’s roster l

Do you know if I can get registered users from the whole server? or for example search a specific user if it is registered or not?

Hi Wael,

Thank you so much for your reply.

now i am able to get the user’s roster items if the user having roster items.

But i want to get all registered users. how to get all the available users?

I want to create chat app using Android.

i want to know the relation between user and roster to make chat app. So, could you suggest me document link for understanding the server?

I explored google but did not get luck !

Please help me…


I don’t know how to get all registered users. Could you help me?

Thanks in advance…

All what you need is to read the smack documentation and understand how xmpp work that’s it

XMPP Extensions – The XMPP Standards Foundation

You can use search form to find users:

public List<HashMap<String, String>> searchUsers(String userName) {

if (connection == null || !connection.isConnected())

return null;

HashMap<String, String> user = null;

List<HashMap<String, String>> results = new ArrayList<HashMap<String, String>>();

try {

UserSearchManager usm = new UserSearchManager(connection);

Form searchForm = usm.getSearchForm(“search.” + connection.getServiceName());

Form answerForm = searchForm.createAnswerForm();

UserSearch userSearch = new UserSearch();

answerForm.setAnswer(“Username”, true);

answerForm.setAnswer(“search”, userName);

ReportedData data = userSearch.sendSearchForm(connection, answerForm, “search.” + connection.getServiceName());

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


user = new HashMap<String, String>();

user.put(“Username”, row.getValues(“Username”).toString());



} catch (Exception e) {



return results;


@Wael, Thanks for your reply.

Could you please tell me which nadroid-smack jar working properly?

And can you provide sample code for getting connection and insert new users through android?

Thanks in advance … latest one even alpha works fine

AccountManager (smack 4.0.1 API)

@wael, Thanks for your help

Hi Wael,

I am tried to connect openfire server from android client by using above above links api. But i am unable connect.

Could you please provide sample code?

Thanks in advance…