目前我正在使用Xmpp SMACK API进行聊天应用。但是当我调用addrosterListener时,我没有获得Presence当前状态。我必须参考 http://www.igniterealtime.org/builds/smack/docs/3.2.2/javadoc/org/jivesoftware/smack/RosterListener.html。请帮助我。
roster.addRosterListener(new RosterListener() {
@Override
public void presenceChanged(Presence presence) {
Log.d("pewsence ", "pewsence Status: " + presence.getFrom());
Log.d("pewsence ", "pewsence to Status: "
+ presence.getTo() + " " + presence);
// Called when the presence of a roster entry is
// changed
}
@Override
public void entriesUpdated(Collection<String> arg0) {
// Called when a roster entries are updated.
}
@Override
public void entriesDeleted(Collection<String> arg0) {
// Called when a roster entries are removed.
}
@Override
public void entriesAdded(Collection<String> arg0) {
// Called when a roster entries are added.
}
});
}
}
});
这个监听器是在创建活动时调用的。我想参考所有文档,当presense发生变化时会自动调用这个监听器。
提前致谢。
答案 0 :(得分:1)
roster = connection.getRoster();
// Get all rosters
Log.i("roster", "roster=" + connection.isConnected() + "-" + roster);
Collection<RosterEntry> entries = roster.getEntries();
// loop through
for (RosterEntry entry : entries) {
Presence entryPresence = roster.getPresence(entry.getUser());
Presence.Type userType = entryPresence.getType();
}
使用此代码,您必须获得所有在线或离线用户。您可以与任何人聊天。