XMPP aSmack - How can I get the current user state (offline/online/away/etc.)?

samsad picture samsad · Jan 22, 2013 · Viewed 11.2k times · Source

I am new to xmpp/asmack in android.

Can anyone please help me in getting the presence of the user's friends ( roster list)

I am using this :

Presence availability = roster.getPresence(user);
Mode userMode = availability.getMode();

What else should I do to get the availability status of each user listed in my roster.

Answer

Gaurav Arora picture Gaurav Arora · Jan 22, 2013

Just use like this :

Presence availability = roster.getPresence(user);
Mode userMode = availability.getMode();

retrieveState_mode(availability.getMode(),availability.isAvailable());

public static int retrieveState_mode(Mode userMode, boolean isOnline) {
        int userState = 0;
        /** 0 for offline, 1 for online, 2 for away,3 for busy*/
        if(userMode == Mode.dnd) {
            userState = 3;
        } else if (userMode == Mode.away || userMode == Mode.xa) {   
            userState = 2;
        } else if (isOnline) {
            userState = 1;
        }
        return userState;
}

Let me know if you have any problem regarding xmpp/asmack