adding user in roster list isn't working

2019-04-03 06:22发布

I am creating an simple one to one chat app, I've done with the message send and receive. Now I am trying to show the status of the user to another(contacts) like "online/offline" etc. For that I have to use Presence and Roster.But I don't know where and how to use that, I mean the complete flow of subscription request and accept and after the subscription, the status of the users i.e. Online/Offline etc.

标签: android xmpp
1条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-04-03 06:45

First of all you need to send and accept contact request

From Open-fire you can also do it from back-end

Steps : First click on Users/Groups >> click on "UserName" >> click on roster >> add roster

Here i attach screen of steps

  • click on add new item

click on add new item

  • add roster add roster

  • edit roster and select subscription both edit roster and select subscription both

then after you will get roster list using this code

ArrayList<RosterEntry> rosterLists = new ArrayList<>();

 public List<RosterEntry> getFriendsList() throws SmackException.NotLoggedInException, InterruptedException, SmackException.NotConnectedException {
    rosterLists = new ArrayList<>();
    roster = Roster.getInstanceFor(Config.conn1);//connection object of AbstractXMPPConnection
    if (!roster.isLoaded()) {
        roster.reloadAndWait();
        Log.e("Roster :", "Reload and wait");
    }

    Collection<RosterEntry> entries = roster.getEntries();
    Log.e("Size of Roster :", entries.size() + "");

    for (RosterEntry entry : entries) {
        rosterLists.add(entry);
        Log.d("Buddies", "Here: " + entry.toString());
        Log.d("Buddies", "User: " + entry.getUser());//get userinfo
        Log.d("Buddies", "User Name:" + entry.getName());//get username
        Log.d("Buddies", "User Status: " + entry.getStatus());//get status of user
    }
    listAdapter = new FriendUserListAdapter(UserListActivity.this, rosterLists);
    user_list.setAdapter(listAdapter);
    return rosterLists;
}

what is the difference between subscription type both and from??? When any user add bot has his/her contact, then in the end of whole process, subscription status of ofRoster(openfire) table is set to ‘from’. The desired result of this process is ‘both’

查看更多
登录 后发表回答