How to add user only to my roster?

I need to add user to another user’'s friends list.

This is what I am doing:

user1 login to XMPP server.

user2 login to XMPP server.

String userId = "";

String userName = “user1”;

Roster r1 = XMPPConnection().getRoster();

r1.createEntry(userId, userName, groups);

The problem is that I see user1 in the roster.getEntries() of user1 and in the roster.getEntries() of user2.

How can I make it be only in the roster.getEntries() of user2? or, if I can not, how can I identify who created this entry?


I do not know what you are trying to achieve but maybe I can add a little background information. The Roster is not only your “business card storage”. It also contains information about the presence subscriptions (more information can be found here).

The state of the presence subscription is reflected in both roosters. You cannot get rid of one entry. The only possibility to figure out what entry was created yourself is adding your (self created) roster entries to a speific roster group.

Hope this helps


I need, to get from the server, list of the users I marked in my cients as the users I am interested in. So next time I’'m entering my client I will be able to present it to the user.

So I guess the right question is: how to get list of the users I’'m interested in.

I assumed that I shoul duse the roster ofr that. If this is not the case, what is the right mechanism to use?


I highly recommend reading the specific part about the roster in the RFC (see link above). As mentioned the Roster is not a “business card repository”. It also reflects the status of each user in your roster. The entries are maintained in both rosters (this is why you have to accept that someone adds you to his roster.

Group membership of an entry is not shared. you could therfore create a group “myentries” (myRoster.createGroup(“myentries”)). Then add all entries to this group (myRoster.createEntry(“bla”,“bla”,new String[] { “myentries” } )).

To get only “your” entries you would then request the roster group myentries (myRoster.getGroup(“myentries”).getEntries()). To obtain all other entries you would grap the unfiled entries (myRoster.getUnfiledEntries()).

It is a bit ugly but most likely the only solution working with the roster. Another possibility could be to store your list into your own VCard. But this is certaindly not less ugly than the first solution.