powered by Jive Software

Presence of roster does not function

I have a roster which I iterate through to get the presence info.

I can see that all the entries are iterated but the presence for all is null

Presence presence = roster.getPresence(entry.getUser());

gives presence = null

Now I know you need to be subscribed to each other to make this happen and I am subscribed and subscription = both.

I have Gaim opened and see the subscription = both but yet it is not noticed. Does anybody have a solution?

My code:

public String any_person_available (XMPPConnection conn, String emailgroup) {

Roster roster = conn.getRoster();

Presence presence;

RosterEntry entry;

for (Iterator i=roster.getEntries(); i.hasNext(); ) {

entry = (RosterEntry) i.next();

if (entry != null) {

presence = roster.getPresence(entry.getUser());

if (presence == null) {

System.out.println(“Presence is null”);

}

System.out.println(“Present are:”);

System.out.println(entry.getUser());

if (presence != null && presence.getType() == Presence.Type.AVAILABLE) {

// aanwezig dus klaar, return deze persoon

return entry.getUser();

}

}

}

return null;

}

When are you checking the presence? This is an asynchronous process, so it takes a few seconds after connecting to see the other contacts.

I did some analysis with smack debug window and it seems that I do not get the correct present info received.

After my request I get:

This is probably because after the presence check I close the connection.

Hello Anlumo,

I did not see your post. I think you might be right,

what I do is connect, check presence and disconnect.

I will try to add a timer and see if I get messages than. Keep you posted.

I added 1 second of waiting and you proved right, thanks.