我尝试设置在线模式,但它无法通过名册工作。我运行此代码并检查我的本地主机服务器,模式仍然“可用”而不是“请勿打扰”。
final Connection connection = new XMPPConnection("xxx.xxx.x.xx");
connection.connect();
connection.login("hieugioi@hieund", "123456");
final Roster roster = connection.getRoster();
Presence p = roster.getPresence("hieugioi@hieund");
p.setPriority(128);
p.setMode(Mode.dnd);
因为你没有将 Presence 数据包发送到服务器。组装好状态数据包后,您需要发送它。例如:
Presence p = new Presence(available, "I am busy", 42, Mode.dnd);
connection.sendStanza(p);
使用 Smack 4.4.4 和 Kotlin,您可以通过这种方式设置状态(仅在断开连接时显示不可用):
if (connection != null){
var pb = connection!!.stanzaFactory.buildPresenceStanza()
.ofType(Presence.Type.unavailable)
.setMode(Presence.Mode.away)
connection!!.sendStanza(pb.build())
connection!!.disconnect()
}