PrivacyListManager.getInstanceFor - NULL in android aSmack

I use the aSmack library to implement the connection to the XMPP server. Connection and chat are working fine. But when I implement user lock using PrivacyManagerList, it returns NULL.

public void blockUser(String listName, String user) {
        // Set the name of the list
        listName = "newList";

        String groupName = "enemies";
        ArrayList privacyItems = new ArrayList();

        PrivacyItem item = new PrivacyItem(PrivacyItem.Type.jid.toString(),
                true, 1);
        item.setValue(user);
        privacyItems.add(item);

        // Get the privacy manager for the current connection.
        PrivacyListManager privacyManager = PrivacyListManager
                .getInstanceFor(connection);
        // Create the new list.
        try {
            privacyManager.createPrivacyList(listName, privacyItems);
        } catch (XMPPException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

This code is from the documentation, but it does not work. PrivacyListManager is always null. Please, I need help to solve this problem. Thanks!

+4
source share
2 answers

just use Class.forName (PrivacyListManager.class.getName ()); up to XMPPConnection.connect ();

+1
source

Using

PrivacyListManager privacyManager = new PrivacyListManager(connection);
0
source

Source: https://habr.com/ru/post/1523996/


All Articles