使用smack和开放式消息服务器拦截用户在聊天列表中的问题
我想通过XMPP
阻止聊天列表中的特定朋友。 代码工作正常。 没有例外,但我无法阻止用户。 我正在使用明火服务器。 我应该在服务器上做什么修改?
你们有什么想法吗?
我的代码:
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的对象中用true替换false
我认为这个问题应该是下列之一:
我建议你仔细阅读文档Smack文档
// 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<PrivacyItem> privacyItems = new Vector<PrivacyItem>();
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;
}
链接地址: http://www.djcxy.com/p/73955.html
上一篇: Issue in blocking user in chatlist using smack and open fire server