Android基于XMPP Smack Openfire下学习开发IM对分组、好友和头像等一些操作
一、查询所有分组
通过Roster来获取所有分组,Roster可以通过connection.getRoster()来得到。
[java]
<SPAN style="WHITE-SPACE: pre"> </SPAN>/**
* 获取所有组
*
* @param roster
* @return 所有组集合
*/
public static List<RosterGroup> getGroups(Roster roster) {
List<RosterGroup> grouplist = new ArrayList<RosterGroup>();
Collection<RosterGroup> rosterGroup = roster.getGroups();
Iterator<RosterGroup> i = rosterGroup.iterator();
while (i.hasNext()) {
grouplist.add(i.next());
}
return grouplist;
}
/**
* 获取所有组
*
* @param roster
* @return 所有组集合
*/
public static List<RosterGroup> getGroups(Roster roster) {
List<RosterGroup> grouplist = new ArrayList<RosterGroup>();
Collection<RosterGroup> rosterGroup = roster.getGroups();
Iterator<RosterGroup> i = rosterGroup.iterator();
while (i.hasNext()) {
grouplist.add(i.next());
}
return grouplist;
}
二、添加分组
也一样通过roster来添加分组,groupName 为分组名。
[java]
SPAN style="WHITE-SPACE: pre"> </SPAN>/**
* 添加一个分组
*
* @param roster
* @param groupName
* @return
*/
public static boolean addGroup(Roster roster, String groupName) {
try {
roster.createGroup(groupName);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
/**
* 添加一个分组
*
* @param roster
* @param groupName
* @return
*/
public static boolean addGroup(Roster roster, String groupName) {
try {
roster.createGroup(groupName);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
三、查询某个组里面的所有好友
很简单不解释...
[java]
<SPAN style="WHITE-SPACE: pre"> </SPAN>/**
* 获取某个组里面的所有好友
*
* @param roster
* @param groupName
* 组名
* @return
*/
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;
}
/**
* 获取某个组里面的所有好友
*
* @param roster
* @param groupName
* 组名
* @return
*/
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;
}
四、查询所有好友信息
很简单
[java]
<SPAN style="WHITE-SPACE: pre"> </SPAN>/**
* 获取所有好友信息
*
* @param roster
* @return
*/
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;
}
/**
* 获取所有好友信息
*
* @param roster
* @return
*/
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;
}
五、获取用户VCard信息
[java]
<SPAN style="WHITE-SPACE: pre"> </SPAN>/**
* 获取用户VCard信息
*
* @param connection补充:移动开发 , Android ,