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("USERNAME@gmail.com", "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));
}
}
这是我在服务中编写的代码。我在我的服务类中持有 xmpp 连接对象。从我调用这些方法的活动中。我可以登录,我可以在 logcat 中看到日志。但是当我调用 displayBuddyList 时我无法获取好友列表()。