你好,我正在为服务器使用 xmpp 和 open-fire 在 android 中开发一个聊天应用程序,
目前我可以创建新用户并使用该用户登录。
我在网上搜索了很多并尝试了不同的解决方案,但没有任何效果。
在服务器上,所有用户都会自动添加到一个默认组中。当创建新用户时。
但在我将他们添加到我的花名册之前我无法获得所有用户的列表。
我的要求是显示所有用户的列表并允许用户从他们那里添加 friend ,如何让所有用户列出那些不是我 friend 的人?
我已经尝试从组中获取用户列表,但仍然没有成功,我只能使用以下代码检索我的 friend 的用户列表。
Roster roster = xmppConnection.getRoster();
Collection<RosterEntry> entries = roster.getEntries();
for(RosterEntry entry1 : entries)
{
System.out.println("UserID:- " + entry1.getUser());
System.out.println("Name:- " + entry1.getName());
System.out.println("Status:- " + entry1.getStatus());
System.out.println("type:- " + entry1.getType());
}
使用以下代码从组中检索用户条目
Roster roster = xmppConnection.getRoster();
Collection<RosterGroup> groups = roster.getGroups();
for(RosterGroup group: groups )
{
System.out.println("Group Name:- " + group.getName());
Collection<RosterEntry> entries = roster.getEntries();
for(RosterEntry entry1 : entries)
{
System.out.println("UserID:- " + entry1.getUser());
System.out.println("Name:- " + entry1.getName());
System.out.println("Status:- " + entry1.getStatus());
System.out.println("type:- " + entry1.getType());
}
}
感谢任何帮助/解决方案或获取所有用户列表的建议。
谢谢。
最佳答案
以下代码对我有用:
UserSearchManager usm = new UserSearchManager(connection);
Form searchForm = usm.getSearchForm("search." + connection.getServiceName());
//Here i am searching for the service name
Form answerForm = searchForm.createAnswerForm();
UserSearch userSearch = new UserSearch();
answerForm.setAnswer("Username", true);
answerForm.setAnswer("search", "*");
ReportedData data = userSearch.sendSearchForm(connection, answerForm, "search." + connection.getServiceName());
if (data.getRows() != null) {
System.out.println("not null");
Iterator<ReportedData.Row> it = data.getRows();
arryAllUsers.clear();
while (it.hasNext()) {
//System.out.println("row");
ReportedData.Row row = it.next();
Iterator iterator = row.getValues("jid");
if (iterator.hasNext()) {
String jid = iterator.next().toString(); //here i get all the user's of the open fire..
// l.add(value);
}
// Log.i("Iteartor values......"," "+value);
}
}
关于java - 从 Android 中的 Openfire 服务器获取所有用户的列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25132437/