我是新手機android和xmpp ..我正嘗試使用xmpp構建聊天應用程序。我想知道如何設置我的存在,並讓其他用戶出現在xmpp android中。我試着用他們提供的文檔,但它不工作..總是狀態顯示爲空,並鍵入爲不可用。請發佈詳細的答案。如何在xmpp中設置和獲取狀態android
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);
}
});
請加你已經嘗試過的一些代碼 - 它更容易幫助你呀 – Cory
@Cory添加了代碼.. – Arjun090