powered by Jive Software

Block /UnBlock user using android

just, i have block the user following snippet code:

`public void XMPPAddNewPrivacyList(XMPPConnection connection, String userName) {

String listName = “newList”;
List privacyItems = new Vector();

PrivacyItem item = new PrivacyItem(PrivacyItem.Type.jid,
userName,false, 1l);
privacyItems.add(item);
// Create the new list.

try {
PrivacyListManager privacyManager;
privacyManager = PrivacyListManager
.getInstanceFor(connection);
privacyManager.createPrivacyList(listName, privacyItems);

} catch (XMPPException e) {
System.out.println("PRIVACY_ERROR: " + e);
}
}`

just call the above method here…

XMPPAddNewPrivacyList(XmppConnection.getInstance().getConnection(), "91xxxxxxxxxx");

after call that above method i got a response like this

`





`

It’s working successfully. I referred whatsapp, we cannot able to send the message which we blocked. as well as if they send the message , we are not receiving that message. But here, i can send and receive the message after i blocked that user. I don’t know why if any one know please let me know.

1 Like

Hello, I am facing the same issue, did you get the solution?

Note that this thread is 3 years old.
By glancing at the code I’d assume that possible sources of errors are:

  • You did not use a bare Jid (i.e. user@server.tld, NOT user, NOR user@server.tld/resource) when creating the PrivacyItem
  • You did not set the list you added the user to as active by calling PrivacyManager.setActiveListName().

Edit: If anyone has enough spare time; the Privacy code in Smack could use some love :wink:

1 Like

Thanks @Paul_Schaub for your quick response, PrivacyManager.setActiveListName() - this was missing in my code,however i tried with privacyManager.setDefaultListName(“list_name”) and it is working too :slight_smile: