上一篇主要是会话的管理
继续,这是显示用户列表方面的
1. 用户列表
Smack主要使用Roster进行列表管理的
connection.getRoster();
[java] view plaincopyprint?
/**
* 返回所有组信息 <RosterGroup>
*
* @return List(RosterGroup)
*/
public static List<RosterGroup> getGroups(Roster roster) {
List<RosterGroup> groupsList = new ArrayList<RosterGroup>();
Collection<RosterGroup> rosterGroup = roster.getGroups();
Iterator<RosterGroup> i = rosterGroup.iterator();
while (i.hasNext())
groupsList.add(i.next());
return groupsList;
}
/**
* 返回相应(groupName)组里的所有用户<RosterEntry>
*
* @return List(RosterEntry)
*/
public static List<RosterEntry> getEntriesByGroup(Roster roster,
String groupName) {
List<RosterEntry> EntriesList = new ArrayList<RosterEntry>();
RosterGroup rosterGroup = roster.getGroup(groupName);
Collection<RosterEntry> rosterEntry = rosterGroup.getEntries();
Iterator<RosterEntry> i = rosterEntry.iterator();
while (i.hasNext())
EntriesList.add(i.next());
return EntriesList;
}
/**
* 返回所有用户信息 <RosterEntry>
*
* @return List(RosterEntry)
*/
public static List<RosterEntry> getAllEntries(Roster roster) {
List<RosterEntry> EntriesList = new ArrayList<RosterEntry>();
Collection<RosterEntry> rosterEntry = roster.getEntries();
Iterator<RosterEntry> i = rosterEntry.iterator();
while (i.hasNext())
EntriesList.add(i.next());
return EntriesList;
}
这里注意下,与gtalk通讯,貌似gtalk是没有分组的,汗,所以使用第三个方法直接取
当然,还要处理,若是刚注册用户,一个组都没有的,需要默认两个组,我的好友及黑名单
黑名单的消息,一律杀掉,不会接受处理
2. 用户头像的获取
使用VCard,很强大,具体自己看API吧
可以看看VCard传回来XML的组成,含有很多信息的