[英]How to get list of offline/online users in chat by using smack api in android
I am writing a chat application in android by using xmpp and smack api. 我正在使用xmpp和smack api在android中编写聊天应用程序。 Chat is working successfully when i am entering email id of particular friend for sending chat.but i am not able to get list of offline/online users.Please suggest how to get list of users using xmpp smack ..?
当我输入特定朋友的电子邮件ID发送聊天时聊天工作成功。但是我无法获得离线/在线用户列表。请建议如何使用xmpp smack获取用户列表..?
You have to make a listView to get list of users and try this code 您必须创建listView以获取用户列表并尝试此代码
public static ArrayList<HashMap<String, String>> usersList=new ArrayList<HashMap<String, String>>();
Presence presence = new Presence(Presence.Type.available);
Constants.connection.sendPacket(presence);
setConnection(Constants.connection);
final Roster roster = Constants.connection.getRoster();
Collection<RosterEntry> entries = roster.getEntries();
for (RosterEntry entry : entries) {
HashMap<String, String> map = new HashMap<String, String>();
Presence entryPresence = roster.getPresence(entry.getUser());
Presence.Type type = entryPresence.getType();
map.put("USER", entry.getName().toString());
map.put("STATUS", type.toString());
Log.e("USER", entry.getName().toString());
usersList.add(map);
}
And then add your userList to your ListAdapter and check STATUS is equals to 'avialable' then the user is online otherwise user is Offline. 然后将您的userList添加到ListAdapter并检查STATUS是否等于'avialable'然后用户在线,否则用户处于离线状态。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.