简体   繁体   中英

adding user in roster list isn't working

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 ie Online/Offline etc.

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

点击添加新项目

  • add roster 添加花名册

  • 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'

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM