powered by Jive Software


HI! How I can get the presence of ALL my contact when I begin de connection??? I got the contacts with a Roster, but the presence not…


Roster# getPresence(String user)

This will return the Presence of the user, so you could iterate over your RosterEntries and return the presence for each user.

Well, when I do that, getPresence returns NULL for all users, but I will do it again…

Roser#getPresence(String user) will return null if the contact has no presence information available. This could be because the contact is offline or you are not subscribed to their presence

Presence information also may not be available the second you logon as it takes a moment for the server to send the corresponding available packets from your roster. You may instead register a listener to listen for the presence packets and then view the updated roster accordingly.

Can you give me a short example of that listener that you said???



and contacto.getCorreo() is oscareduardo@12jabber.com who is ONLINE

and it print NULL

Message was edited by: hadesandres

If you are getting null when your contact is online then it will be (most likely) one of two things.

1: Either you are not subscribed to the other contacts Presence. In which case you will need to before you are allowed to track their Online/Offline status


2: As AWenckus mentioned, it can sometimes take a moment for the information to be sent so if you are performing this operation as soon as you login the method may well return null.

Far better to add a RosterListener to your connection to listen out for Presence changes

I did the listener for the presence:

public class PresenceListener implements PacketListener {

public void processPacket(Packet packet) {

Presence presence = (Presence)packet;

Presence.Type presenceType = presence.getType();

if(presenceType == Presence.Type.AVAILABLE){


System.out.println(packet.getFrom()+" is OnLine");


if(presenceType == Presence.Type.SUBSCRIBE) {

// do something with subscribing


if(presenceType == Presence.Type.SUBSCRIBED) {

// do something with letting user know someone has subscribed




BUT I have another question: When another client set her/his presence in BUSY or AWAY, the incoming package tell me that he is AVAILABLE… How I can know the type of each presence??? (AWAY - BUSY - ANOTHER)


Well you could read the API docs

What you are talking about can be found by getting the Mode of the Presence packets you are being sent.


Presence presence = (Presence)packet;

Presence.Mode presenceMode = presence.getMode();

if(presenceMode == Presence.Mode.AVAILABLE) {

// user is online and available


if(presenceMode == Presence.Mode.AWAY) {

//user is away



hth Jon

JAJAJA HI John, you´re right, the problem was I have “presence.getType()” so it show me only available, unavailable…etc…

You can explain me the difference between:

  • Subscribe

  • Subscribed

  • Unsubscribe

  • Unsubscribed

Thanks a lot!


From the Java Docs

  1. Presence.Type.SUBSCRIBE – request subscription to recipient’'s presence.

  2. Presence.Type.SUBSCRIBED – grant subscription to sender’'s presence.

  3. Presence.Type.UNSUBSCRIBE – request removal of subscription to sender’'s presence.

  4. Presence.Type.UNSUBSCRIBED – grant removal of subscription to sender’'s presence.

They be wonderful things

HI! JonWright; well of course I saw that in the Java Docs… but I need more words for that because I don´t understand for example “grant subscription to sender’'s presence.”

Thanks for your help


Okay, take for example two users

User A

User B

User A wants to see when User B is online.

User A sends a SUBSCRIBE packet to User B

User B then decides whether or not to allow User A to see when they are online.

If they accept the subscription requests they send a


If they reject the subscription request they send a




ah! THANKS that help resolve more questions that I had…

Thanks for your help…

No problem, I know what its like to be stuck

Can user B see user A online if the SUBSCRIBED packet is sent?

I think my experience tells me no, but I’'m not sure.

So if I want User B to See User A at the end of this process, what to you recommend?

Presence is a two way street. You can allow someone to see your Online/Offline Presence but you might not be interested in seeing theirs. So when someone asks to SUBSCRIBE and you send a SUBSCRIBED packet they will see your Online/Offline Presence but you wont see theirs.

Obviously, one of the main reasons for people using Instant Messaging apps is so they can talk to one another, due to this, most apps will automatically send a SUBSCRIBE packet to a User if they have sent a SUBSCRIBED packet, or at least ask the user if they want to send one.

Along with this reasoning, most apps automatically send SUBSCRIBED packet if they have already SUBSCRIBED to your presence.



HI! i’‘m again… I have a question about this topic… When I send (USER A) a SUSCRIBE Packet, the server returns me an instant SUSCRIBED packet… and don’'t tell the user B the request…

Is there any way the server don’'t return this suscribed packet and the user B can response a SUSCRIBED or UNSUSCRIBED packet???



You need to set the subsciption mode of your client, by default it is set to SUBSCRIPTION_ACCEPT_ALL.

If you do something like



then it will force you to manually accept or reject subscriptions to your Presence