Search code examples
androidchatasmackquickblox

Get user are online or not, by using QuickBlox


I'm using QuickBlox as BaaS. I would like to try getting user status. Are they online or not ? Found below useful question and I used Roster. Can I get online users in my friend list via Smack?

But When I retrieve by implementing following, get null entries.

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());
    }

Solution

  • In order to use this code you should add some users to your Roster (Contact list).

    While adding some users - these users will receive Roster request and will be able to add you as well.

    After that you Roster will contain some entries and you can iterate through it.