2012-07-26 60 views
0
public boolean connect() { 
    String host = "talk.google.com"; 
    String port = "5222"; 
    String service = "gmail.com"; 

    ConnectionConfiguration connConfig = new ConnectionConfiguration(host, 
      Integer.parseInt(port), service); 
    connection = new XMPPConnection(connConfig); 

    try { 
     connection.connect(); 
     log("xmpp connected"); 
     connection.login("[email protected]", "Password"); 
     log("user loged in"); 
     log("loged user : " + connection.getUser()); 
    } catch (XMPPException e) { 
     e.printStackTrace(); 
     return false; 
    } 
    return true; 
} 

public void displayBuddyList() { 
    String user; 
    String status_Message; 
    int state; 
    Roster roster = connection.getRoster(); 
    Collection<RosterEntry> entries = roster.getEntries(); 

    log("Buddy list size :"+entries.size()); 
    for (RosterEntry r : entries) { 

     user=r.getUser(); 
     status_Message=retrieveStatusMessage(user); 
     log("name: "+r.getName()+" user :"+user+" Status :"+status_Message+" type :"+retrieveState(user)); 

    } 
} 

這是我寫的service.Im控股XMPP連接對象在我的服務class.From活動IM調用這些methods.I可以登錄,我可以看到在logcat.But我」的日誌代碼當我調用displayBuddyList()時無法獲得好友列表。無法getBuddylist XMPP

回答

1
Roster roster = XMPPConnection.getRoster(); 
     Collection<RosterEntry> entries= roster.getEntries(); 
     ProviderManager.getInstance().addIQProvider("vCard", "vcard-temp", 
       new VCardProvider()); 
     VCard card = null; 
     for (RosterEntry entry : entries) { 
      card = new VCard(); 
      Presence presencek= roster.getPresence(entry.getUser()); 
      try { 
       card.load(Main.conn, entry.getUser()); 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 

      String jid = entry.getUser(); 
      String name = card.getField("FN"); 
      String status = presencek.getType().name(); 
      Log.d("Prescence", "" + presencek.getType().name());// //num one log 

      byte[] imgs = card.getAvatar(); 
      if (imgs != null) { 
       int len = imgs.length; 
       Bitmap img = BitmapFactory.decodeByteArray(imgs, 0, len); 
      } 

看到這樣一個https://stackoverflow.com/questions/9885154/how-to-get-images-from-xmpp-in-android-application/10272947#10272947

+0

WATS錯在我的代碼..?我得到的錯誤「主」是未知的代碼。 – Meher 2012-07-26 11:42:37

+0

我正在使用asmack-2010.05.07-source – Meher 2012-07-26 11:43:28

相關問題