2012-03-29 67 views
1

我想獲取名單中某個人的所有(活動)資源的列表。 因此,例如「[email protected]」如果該用戶當前通過GMail('[email protected]/gmail')和Pidgin登錄,我想獲得類似{'gmail', 'pidgin'}的內容。獲取名單條目的所有資源列表

Smack有可能嗎?我知道有些客戶顯示這些信息,例如XMPPHP支持類似getResources(),但XMPPHP適用於PHP,不適用於Google Talk,因此對我沒有多大幫助。

問候

回答

3

隨着揍你需要的,因爲他們收到的跟蹤存在數據包。收到的數據包的「from」將包含用戶JID的資源。

例如:

private XMPPConnection connection; 
private PresenceListener listener = new PresenceListener(); 

public void setConnection(XMPPConnection connection) { 
    this.connection = connection; 
} 

public void createPresenceListener() { 
    connection.addPacketListener(listener, new PacketTypeFilter(Presence.class)); 
} 

public static class PresenceListener implements PacketListener { 
    public void processPacket(Packet packet) { 
     Presence presence = (Presence) packet; 
     if (presence.getType() == null || presence.getType() == Presence.Type.available) { 
      String from = presence.getFrom(); 
      if (from != null && from.lastIndexOf("/") > 0) { 
       String resource = from.substring(from.lastIndexOf("/") + 1); 
       // from here you can track all active resources 
      } 
     } 

    } 
} 
+0

大,這工作 - 非常感謝你! – 2012-03-30 06:02:41

相關問題