2012-06-26 3 views
2

실제로 스맥 API를 사용하여 IM 서비스 (상속 된 Google 채팅)를 프로그래밍합니다. 하지만 친구 목록과 프리젠 테이션을 인쇄하려고 할 때 컴파일 모드는 모든 프리젠 스를 사용할 수 없음을 보여 주지만 디버그 모드에서는 실제 가용성을 보여줍니다!스맥 존재가 작동하지 않습니다.

내 코드는 ...

1- 연결 작성

public boolean openConnection() { 
    ConnectionConfiguration connectionConfiguration = new ConnectionConfiguration("talk.google.com", 5222, "mail.google.com"); 
    this.connection = new XMPPConnection(connectionConfiguration); 
    try { 
     this.connection.connect(); 
    } catch (XMPPException e) { 
     // TODO: Send Error Information To Programmer's Email Address 
    } 
    if(this.connection.isConnected()) { 
     this.roster = this.connection.getRoster(); 
     this.roster.addRosterListener(new RosterListener() { 
      public void entriesAdded(Collection<String> addresses) {} 
      public void entriesDeleted(Collection<String> addresses) {} 
      public void entriesUpdated(Collection<String> addresses) {} 
      public void presenceChanged(Presence presence) {} 
     }); 
     return true; 
    } 
    return false; 
} 

2- 로그인

public boolean login(String jid, String password) { 
    try { 
     this.connection.login(jid, password, "smack"); 
    } catch (XMPPException e) { 
     // TODO: Send Error Information To Programmer's Email Address 
    } 
    if(this.connection.isAuthenticated()) return true; 
    return false; 
} 

-3- 버디리스트

public void buddiesList() { 
    Collection<RosterEntry> rosterEntries = this.roster.getEntries(); 
    for(RosterEntry rosterEntry: rosterEntries) { 
     System.out.println(rosterEntry.username() + " === " + this.roster.getPresence(rosterEntry.getUser())); 
    } 
} 

4- 구현

public static void main(String args[]) { 
    IMService imService = new IMService(); 
    imService.openConnection(); 
    imService.login("google account", "password"); 
    imService.buddiesList(); 
} 

답변

1

RosterListener가 아무 것도하지 않습니다. 이것은 현재 상태 메시지와 같은 것이 수신 될 때 명단을 업데이트하는 코드를 넣어야하는 곳입니다.

검색중인 상태는 상태를 생성 한 시점의 스냅 샷입니다. 현재 상태를 유지하려면 RosterListener를 실제로 코딩해야합니다. 이것은 Javadoc for the getPresence() 방법에 명시되어 있습니다.

관련 문제