Hi,
I am using the below code to fetch all the contacts but presence.getStatus not always returning the contacts status.
-
connected to openfire server
-
loged into openfire server
-
Called the below function
Putting a arbitary sleep is not a proper solution. Also if i add presense listener that is a solution when a user is changing his presense. This will not catch initial presense while retreiving all the contacts.
Please help to solve this common problem.
**Why **presencestatus = p.getStatus(); is null but not always ??
public boolean XMPPRetreiveRosters(Roster roster,ArrayList AllContacts)
{
Collection entries = roster.getEntries();if(entries == null) return false; Iterator it = entries.iterator(); String username = null; String userid = null; String presencetype = null; String presencemode = null; String presencestatus = null; String usergroupname = null; if(it.hasNext() == false) return false; while(it.hasNext()) { String contacts = ""; RosterEntry entry = (RosterEntry) it.next(); if(entry!=null) { username = entry.getName(); userid = entry.getUser(); } Presence p = roster.getPresence(entry.getUser()); if(p!=null) { Type type = p.getType(); Mode mode = p.getMode(); if(type!=null) { presencetype = type.name(); } if(mode!=null) { presencemode = mode.name(); } presencestatus = p.getStatus(); } Collection collection = entry.getGroups(); Iterator groupIterator = collection.iterator(); while(groupIterator.hasNext()) { RosterGroup rgroup = (RosterGroup) groupIterator.next(); if(rgroup!=null) usergroupname = rgroup.getName(); } XMPPContacts contact = new XMPPContacts(username, userid, presencetype, presencemode, presencestatus, usergroupname); AllContacts.add(contact); contacts += "[ " + username + " ]-[ " + userid + " ]-[ " + presencetype + " ]-[ " + presencemode + " ]-[ " + presencestatus + " ]-[ " + usergroupname + " ]"; } return true; }