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

后端 未结 4 1921
小蘑菇
小蘑菇 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:12

    try this ...

    public boolean blockFriend(String friendName) {
    
        PrivacyItem item=new PrivacyItem(PrivacyItem.Type.jid,friendName, false, 7);
        PrivacyListManager privacyManager = PrivacyListManager.getInstanceFor(connection);
        List list=new ArrayList();
        list.add(item);
    
        try {
            privacyManager.updatePrivacyList(NEWLIST, list);
            privacyManager.setActiveListName(NEWLIST);
            return true;
        } catch (SmackException.NoResponseException |XMPPException.XMPPErrorException | SmackException.NotConnectedException e) {
            e.printStackTrace();
            return false;
        }
    
    
    }
    

    and for unblock just replace false with true in object of privacyitem `

提交回复
热议问题