如何订阅以收听 SMACK 中的用户可用性状态更改?
要获取用户的可用性状态,我使用以下命令:
XMPPConnection.getRoster().getPresence(name).isAvailable();
但是如何订阅以便在状态更改时收到一些通知?(所以我不必投票)。
此代码可以帮助您:
roster.addRosterListener(new RosterListener() {
// Ignored events public void entriesAdded(Collection<String> addresses) {}
public void entriesDeleted(Collection<String> addresses) {}
public void entriesUpdated(Collection<String> addresses) {}
public void presenceChanged(Presence presence) {
System.out.println("Presence changed: " + presence.getFrom() + " " + presence);
}
@Override
public void entriesAdded(Collection<String> arg0) {
// TODO Auto-generated method stub
}
});
roster.addRosterListener(new RosterListener() {
// Ignored events public void entriesAdded(Collection<String> addresses) {}
public void entriesDeleted(Collection<String> addresses) {}
public void entriesUpdated(Collection<String> addresses) {}
public void presenceChanged(Presence presence) {
Log.e(TAG, presence.getStatus());
Log.e(TAG,presence.getFrom());
Log.e(TAG, presence.getLanguage());
Log.e(TAG,presence.getDefaultLanguage());
Log.e(TAG, presence.getType().toString());
}
@Override
public void entriesAdded(Collection<String> arg0) {
// TODO Auto-generated method stub
}
});