I am new to smack API. I am trying to develop a chat application where I tried to install and get a presence.
When I change the user’s presence, his work is beautiful, and he is reflected on the Openfire server.
But when I try to get a User Presence, I always get the status "inaccessible", even if his presence in openfire is displayed as "available".
I use the following code to set the state.
Presence presence = new Presence(Presence.Type.available); presence.setStatus("Online, Programmatically!"); presence.setPriority(24); presence.setMode(Presence.Mode.available); user.getConnection().sendPacket(presence);
I use the Roster class to get the following:
Roster roster = avatar.getRoster(); Collection<RosterEntry> entries = roster.getEntries(); for(RosterEntry rosterEntry: entries) { String user = rosterEntry.getUser(); Presence presence = roster.getPresence(user); System.out.println("Presence : "+presence); // 1 System.out.println("Presence type: "+presence.getType()); // 2 System.out.println("Presence mode: "+presence.getMode()); // 3 }
Line number 1 alwasys gives "unavailable", and lines number 2 and 3 always give zero
I can not understand the cause of this problem. Please help me solve this problem.
Thanks in advance.
smack openfire
Le hoang long
source share