我正在使用一个 Smack 库来实现与 XMPP 服务器的连接。连接和聊天工作正常。但是当我使用 PrivacyManagerList 实现阻止用户时,它返回 NULL。
public void blockUser(String listName, String user) {
// Set the name of the list
listName = "newList";
String groupName = "enemies";
ArrayList privacyItems = new ArrayList();
PrivacyItem item = new PrivacyItem(PrivacyItem.Type.jid.toString(),
true, 1);
item.setValue(user);
privacyItems.add(item);
// Get the privacy manager for the current connection.
PrivacyListManager privacyManager = PrivacyListManager
.getInstanceFor(connection);
// Create the new list.
try {
privacyManager.createPrivacyList(listName, privacyItems);
} catch (XMPPException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
那是文档中的代码,但它不起作用。 PrivacyListManager 始终为空。 拜托,我需要一些帮助来解决这个问题。 谢谢!
最佳答案
只需使用 Class.forName(PrivacyListManager.class.getName()); 前 XMPPConnection.connect();
关于android - PrivacyListManager.getInstanceFor 在 android aSmack 中为 NULL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21397396/