Can I get online users in my friend list via Smack?

chikka.anddev picture chikka.anddev · Jan 12, 2011 · Viewed 14.8k times · Source

Can i get online users in my friend list via Smack API? Is it possible?

I am working on app which have chat between users. I had successfully created chat application example just entering name of friend and send chat, but now I want online friends list.

Answer

Jignesh Dhua picture Jignesh Dhua · Jan 12, 2011
Roster roster = xmppConnection.getRoster();
Collection<RosterEntry> entries = roster.getEntries();
Presence presence;

for(RosterEntry entry : entries) {
    presence = roster.getPresence(entry.getUser());

    System.out.println(entry.getUser());
    System.out.println(presence.getType().name());
    System.out.println(presence.getStatus());
}