我是 android 和 xmpp 的新手。我正在尝试使用 xmpp 构建一个聊天应用程序。我想知道如何设置我的存在并让其他用户在 xmpp android 中存在。我尝试使用他们提供的文档,但它不起作用..总是状态显示为 null 并且类型为不可用。请发布详细答案。
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);
}
});