通过Roster来获取所有分组,Roster可以通过connection.getRoster()来得到。
[java] view plain copy /** * 获取所有组 * * @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] view plain copy /** * 添加一个分组 * * @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] view plain copy /** * 获取所有好友信息 * * @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来获取用户头像信息,可以把 InputStream 转换为自己想要的类型,InputStream 转Drawable
这篇文章里可以找到 http://blog.csdn.net/h7870181/article/details/8663760
[java] view plain copy /** * 获取用户头像信息 * * @param connection * @param user * @return */ public static Drawable getUserImage(XMPPConnection connection, String user) { ByteArrayInputStream bais = null; try { VCard vcard = new VCard(); // 加入这句代码,解决No VCard for ProviderManager.getInstance().addIQProvider("vCard", "vcard-temp", new org.jivesoftware.smackx.provider.VCardProvider()); vcard.load(connection, user+"@"+connection.getServiceName()); if (vcard == null || vcard.getAvatar() == null) return null; bais = new ByteArrayInputStream(vcard.getAvatar()); } catch (Exception e) { e.printStackTrace(); } if (bais == null) return null; return FormatTools.getInstance().InputStream2Drawable(bais); }
serverDoMain 为服务器域名
[java] view plain copy /** * 查询用户 * * @param connection * @param serverDomain * @param userName * @return * @throws XMPPException */ public static List<User> searchUsers(XMPPConnection connection, String serverDomain, String userName) throws XMPPException { List<User> results = new ArrayList<User>(); System.out.println("查询开始..............." + connection.getHost() + connection.getServiceName()); UserSearchManager usm = new UserSearchManager(connection); Form searchForm = usm.getSearchForm(serverDomain); Form answerForm = searchForm.createAnswerForm(); answerForm.setAnswer("userAccount", true); answerForm.setAnswer("userPhote", userName); ReportedData data = usm.getSearchResults(answerForm, serverDomain); Iterator<Row> it = data.getRows(); Row row = null; User user = null; while (it.hasNext()) { user = new User(); row = it.next(); user.setUserAccount(row.getValues("userAccount").next().toString()); user.setUserPhote(row.getValues("userPhote").next().toString()); System.out.println(row.getValues("userAccount").next()); System.out.println(row.getValues("userPhote").next()); results.add(user); // 若存在,则有返回,UserName一定非空,其他两个若是有设,一定非空 } return results; }转载于:https://www.cnblogs.com/jasonkent27/p/4098440.html
相关资源:各显卡算力对照表!