powered by Jive Software

Block User not working properly

Hi am using smack 4.3.4.

When am blocking a user it work until I re-login.

after relogin messages can recieved again even i see user is blocked.

My code is:

public boolean blockContact(Jid jid) {
        String listName = "block-list";
        // Create the list of PrivacyItem that will allow or
        // deny some privacy aspect
        List<PrivacyItem> privacyItems = new Vector<>();
        PrivacyItem item = new PrivacyItem(PrivacyItem.Type.jid, jid, false, 1);
        // Get the privacy manager for the current connection.
        // Create the new list.
        PrivacyListManager privacyManager = PrivacyListManager.getInstanceFor(Connection.getInstance().getXmpptcpConnection());
        try {
            privacyManager.updatePrivacyList(listName, privacyItems);
            return true;
        } catch (Exception e) {
            Log.e("PRIVACY_ERROR: ", " " + e.toString());
        return false;

Please let me know why a user can received message if he blocked and In still in blocked list after relogin.

You seem to be setting the ‘active’ list, instead of the ‘default’ list. The ‘active’ list is ment to be active for the duration of the session only. You can read up about the details in https://xmpp.org/extensions/xep-0016.html

Can you tell me how to set for default list. And after login if go to block contact list am getting contacts list there in the privacy list. with the following code:

PrivacyList plist = null;
        try {
            plist = privacyManager.getPrivacyList("public");
        } catch (NoResponseException e) {
        } catch (NotConnectedException e) {
        if (plist != null) {// No blacklisted or is not listed, direct getPrivacyList error
            List<PrivacyItem> items = plist.getItems();
            for (PrivacyItem item : items) {
                // print item.getValue(); to get ID

Use setDefaultListName() instead of setActiveListName() in the code that you provided.


Thank you @Guus it working now.

This topic was automatically closed 62 days after the last reply. New replies are no longer allowed.