Follow these links to learn how to send and receive roster items:
JEP related: JEP-93// Connect to the server and log in conn1 = new XMPPConnection(host); conn1.login(server_user1, pass1); // Create a new roster exchange manager on conn1 RosterExchangeManager rosterExchangeManager = new RosterExchangeManager(conn1); // Send user1's roster to user2 rosterExchangeManager.send(conn1.getRoster(), user2);
// Connect to the server and log in conn1 = new XMPPConnection(host); conn1.login(server_user1, pass1); // Create a new roster exchange manager on conn1 RosterExchangeManager rosterExchangeManager = new RosterExchangeManager(conn1); // Send user1's RosterGroups to user2 for (Iterator it = conn1.getRoster().getGroups(); it.hasNext(); ) rosterExchangeManager.send((RosterGroup)it.next(), user2);
// Connect to the server and log in conn1 = new XMPPConnection(host); conn1.login(server_user1, pass1); // Create a new roster exchange manager on conn1 RosterExchangeManager rosterExchangeManager = new RosterExchangeManager(conn1); // Send a roster entry (any) to user2 rosterExchangeManager1.send((RosterEntry)conn1.getRoster().getEntries().next(), user2);
// Connect to the server and log in the users conn1 = new XMPPConnection(host); conn1.login(server_user1, pass1); conn2 = new XMPPConnection(host); conn2.login(server_user2, pass2); final Roster user2_roster = conn2.getRoster(); // Create a RosterExchangeManager that will help user2 to listen and accept the entries received RosterExchangeManager rosterExchangeManager2 = new RosterExchangeManager(conn2); // Create a RosterExchangeListener that will iterate over the received roster entries RosterExchangeListener rosterExchangeListener = new RosterExchangeListener() { public void entriesReceived(String from, Iterator remoteRosterEntries) { while (remoteRosterEntries.hasNext()) { try { // Get the received entry RemoteRosterEntry remoteRosterEntry = (RemoteRosterEntry) remoteRosterEntries.next(); // Display the remote entry on the console System.out.println(remoteRosterEntry); // Add the entry to the user2's roster user2_roster.createEntry( remoteRosterEntry.getUser(), remoteRosterEntry.getName(), remoteRosterEntry.getGroupArrayNames()); } catch (XMPPException e) { e.printStackTrace(); } } } }; // Add the RosterExchangeListener to the RosterExchangeManager that user2 is using rosterExchangeManager2.addRosterListener(rosterExchangeListener); // Create a RosterExchangeManager that will help user1 to send his roster RosterExchangeManager rosterExchangeManager1 = new RosterExchangeManager(conn1); // Send user1's roster to user2 rosterExchangeManager1.send(conn1.getRoster(), user2);