我想阻止我的聊天列表中选择一个特别的朋友与 XMPP
。 code正常工作。有没有例外,但我不能够阻止用户。
我使用明火服务器。我应该做在服务器上什么样的变化?
能否能跟大家有什么想法?
我的code:
公共无效XMPPAddNewPrivacyList(连接的连接,用户名字符串){
字符串LISTNAME =newList;
//创建PrivacyItem列表,将允许或
//否认一些隐私方面
名单< PrivacyItem> privacyItems =新矢量< PrivacyItem>();
PrivacyItem项目=新PrivacyItem(PrivacyItem.Type.jid.toString()
假,1);
item.setValue(用户名);
privacyItems.add(项目);
//创建新的列表。
尝试 {
PrivacyListManager privacyManager =新PrivacyListManager(连接);
privacyManager = PrivacyListManager
.getInstanceFor(连接);
privacyManager.createPrivacyList(LISTNAME,privacyItems);
}赶上(XMPPException E){
的System.out.println(PRIVACY_ERROR:+ E);
}
}
解决方案
试试这个...
公共布尔blockFriend(字符串friendName){
PrivacyItem项目=新PrivacyItem(PrivacyItem.Type.jid,friendName,假,7);
PrivacyListManager privacyManager = PrivacyListManager.getInstanceFor(连接);
名单< PrivacyItem>名单=新的ArrayList< PrivacyItem>();
list.add(项目);
尝试 {
privacyManager.updatePrivacyList(NEWLIST,清单);
privacyManager.setActiveListName(NEWLIST);
返回true;
}赶上(SmackException.NoResponseException | XMPPException.XMPPErrorException | SmackException.NotConnectedException E){
e.printStackTrace();
返回false;
}
}
和疏通 只是与真正的替代虚假privacyitem对象`
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 server. what changes should i made on server?
Can u guys have any idea?
My code:
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);
}
}
解决方案
try this ...
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;
}
}
and for unblock just replace false with true in object of privacyitem `