I am new to android and xmpp..i am trying to build a chatting app using xmpp. I want to know How to set my presence and also get other users presence in xmpp android. i tried with their provided documentation but it is not working ..always status shows null and type as unavailable. please post a detail answer.
Roster roster = Roster.getInstanceFor(connection);
//Get all rosters
if (!roster.isLoaded())
try {
roster.reloadAndWait();
} catch (SmackException.NotLoggedInException | SmackException.NotConnectedException | InterruptedException e) {
e.printStackTrace();
}
Collection<RosterEntry> entries = roster.getEntries();
//loop through
for (RosterEntry entry : entries) {
//example: get presence, type, mode, status
Presence entryPresence = roster.getPresence(entry.getUser());
StatusMode statusMode= StatusMode.createStatusMode(entryPresence);
// statusMode.getMode();
Presence.Type userType = entryPresence.getType();
Presence.Mode mode = entryPresence.getMode();
String status = entryPresence.getStatus();
retrieveState_mode(mode,entryPresence.isAvailable());
Log.d("####User status","...."+entry.getUser()+"....."+statusMode+"....."+entryPresence +" \ntype: "+"\n"+userType + "\nmode: " +mode + "\nstatus: " + status);// + "\nType: " + status.getType());
}
roster.addRosterListener(new RosterListener() {
// Ignored events public void entriesAdded(Collection<String> addresses) {}
public void entriesDeleted(Collection<String> addresses) {
}
@Override
public void entriesAdded(Collection<String> addresses) {
}
public void entriesUpdated(Collection<String> addresses) {
}
public void presenceChanged(Presence presence) {
System.out.println("Presence changed: " + presence.getFrom() + " " + presence);
}
});