You can do it as below:
1- Define a roster
private SmackAndroid smackAndroid;
private Roster roster;
2- Inside onCreate, initialize the smackAndroid and add XMPPConnectionListener
smackAndroid = SmackAndroid.init(this);
XMPPConnection.addConnectionCreationListener(new ConnectionCreationListener() {
@Override
public void connectionCreated(Connection connection) {
roster = connection.getRoster();
}
});
3- You can add user to the roster using createEntry
try {
roster.createEntry("UserId", "userName", new String[] { "Friends" });
} catch (XMPPException e) {
e.printStackTrace();
}
4- You can get Entries form roster using getEntry()
ArrayList<String> friends = new ArrayList<String>();
Collection<RosterEntry> entries = roster.getEntries();
for (RosterEntry entry : entries) {
friends.add(entry.getName());
}