我正在尝试开发一个 Xmpp 客户端并显示带有图像的好友列表。我将图像存储在缓存目录中以便快速检索和不必要的网络使用。这里的问题是如果好友更改了他的图像,我如何得到通知以获取新图像来自服务器,而不是来自本地缓存。请建议。
我正在使用 asmack api。
private static XMPPConnection connection;
// If any changes occured in buddylist
connection.getRoster().addRosterListener(new RosterListener() {
@Override
public void presenceChanged(Presence arg0) {
}
@Override
public void entriesUpdated(Collection<String> arg0) {
}
@Override
public void entriesDeleted(Collection<String> arg0) {
}
@Override
public void entriesAdded(Collection<String> arg0) {
}
});
获取用户列表
private ArrayList<HashMap<String, String>> getUserList() throws Exception {
ArrayList<HashMap<String, String>> userList = new ArrayList<HashMap<String, String>>();
if (isConnectionAlive() || reConnectAndAuth()) {
Roster roster = connection.getRoster();
Collection<RosterEntry> entries = roster.getEntries();
for (RosterEntry entry : entries) {
String avatarPath = "";
VCard vCard = new VCard();
try {
vCard.load(connection, entry.getUser());
vCard.getExtensions();
byte[] b = vCard.getAvatar();
Bitmap avatar = BitmapFactory.decodeByteArray(vCard.getAvatar(), 0, b.length);
avatarPath = savaAvatar(avatar, entry.getUser());
} catch (Exception e) {
}
HashMap<String, String> user = new HashMap<String, String>();
user.put("name", entry.getName());
user.put("userid", entry.getUser());
user.put("statusMsg", "" + entry.getStatus());
user.put("user_avatar", avatarPath);
user.put("status", "" + connection.getRoster().getPresence(entry.getUser()).isAvailable());
userList.add(user);
}
}
return userList;
}