Issue in blocking user in chatlist using smack and open fire server

后端 未结 4 1922
小蘑菇
小蘑菇 2021-02-15 17:51

I want to block a particular friend from my chat list with XMPP. code works fine. There is no Exception, but I am not able to block a user. I\'m using open fire ser

4条回答
  •  一生所求
    2021-02-15 18:30

        // Here function for block user on xmpp
    
        public boolean blockUser(String userName) {
    
        String jid = userName@localhost
        String listName = "public";
    
        // Create the list of PrivacyItem that will allow or
        // deny some privacy aspect
    
        //ArrayList privacyItems = new ArrayList();
    
        List privacyItems = new Vector();
    
    
        PrivacyItem item = new PrivacyItem(PrivacyItem.Type.jid, jid, false, 1);
        // item.setValue(userName);
        item.setFilterIQ(false);
        item.setFilterMessage(false);
        item.setFilterPresenceIn(false);
        item.setFilterPresenceOut(false);
    
        privacyItems.add(item);
    
        // Get the privacy manager for the current connection.
    
        // Create the new list.
        PrivacyListManager privacyManager = PrivacyListManager.getInstanceFor(XMPPUtils.INSTANCE.connection);
    
    
        try {
            privacyManager.updatePrivacyList(listName, privacyItems);
            privacyManager.setActiveListName(listName);
    
            return true;
        } catch (Exception e) {
            Log.e("PRIVACY_ERROR: ", " " + e.toString());
            e.printStackTrace();
        }
    
        return false;
    }
    

提交回复
热议问题