Im connecting to an ejabberd XMPP server using Smack API -
username = "admin";
password = "admin";
port = "5222";
serviceName = "davids-macbook-pro.local";
host = "192.168.20.8";
config = XMPPTCPConnectionConfiguration.builder()
.setUsernameAndPassword(username, password)
.setHost(host)
.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)
.setServiceName(serviceName)
.setPort(Integer.parseInt(port))
.build();
connection = new XMPPTCPConnection(config);
try {
connection.connect();
connection.login();
} catch (SmackException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (XMPPException e) {
e.printStackTrace();
}
I want to get a list of all online users. How is it possible ?
When I try -
Roster roster = Roster.getInstanceFor(connection);
Collection<RosterEntry> entries = roster.getEntries();
Log.i("entry", entries+"");
for (RosterEntry entry : entries) {
}
Getting a null array for
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);
}
check STATUS is equals to 'available' then the user is online otherwise user is Offline.
User getPresence
in Roaster
as below.
Roster roster = Roster.getInstanceFor(connection);
Collection<RosterEntry> entries = roster.getEntries();
for (RosterEntry rosterEntry : entries){
System.out.println("xmpp.Roster.presence "+ roster.getPresence(rosterEntry.getUser()).getType());
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.