我想用 XMPP
从我的聊天列表中屏蔽一个特定的 friend 。代码工作正常。没有异常(exception),但我无法阻止用户。
我正在使用明火服务器。我应该在服务器上进行哪些更改?
你们有什么想法吗?
我的代码:
public void XMPPAddNewPrivacyList(Connection connection, String userName) {
String listName = "newList";
// Create the list of PrivacyItem that will allow or
// deny some privacy aspect
List<PrivacyItem> privacyItems = new Vector<PrivacyItem>();
PrivacyItem item = new PrivacyItem(PrivacyItem.Type.jid.toString(),
false, 1);
item.setValue(userName);
privacyItems.add(item);
// Create the new list.
try {
PrivacyListManager privacyManager = new PrivacyListManager(connection);
privacyManager = PrivacyListManager
.getInstanceFor(connection);
privacyManager.createPrivacyList(listName, privacyItems);
} catch (XMPPException e) {
System.out.println("PRIVACY_ERROR: " + e);
}
}
最佳答案
试试这个……
public boolean blockFriend(String friendName) {
PrivacyItem item=new PrivacyItem(PrivacyItem.Type.jid,friendName, false, 7);
PrivacyListManager privacyManager = PrivacyListManager.getInstanceFor(connection);
List<PrivacyItem> list=new ArrayList<PrivacyItem>();
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;
}
}
解锁 只需在 privacyitem 的对象中将 false 替换为 true `
关于android - 使用 smack 和 open fire 服务器在聊天列表中阻止用户的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18610788/