无法使用Smack更改我的用户的在线状态

9

我尝试通过花名册设置在线模式,但无法生效。我运行了这段代码并检查了我的本地主机服务器,模式仍然是“可用”,而不是“请勿打扰”。

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);
1个回答

22
因为您没有向服务器发送“Presence packet”(在线状态包)。在您组装好在线状态包后,需要将其发送。例如:
因为你没有将“Presence packet”发送到服务器。在组装好在线状态包之后,您需要将其发送。例如:
Presence p = new Presence(available, "I am busy", 42, Mode.dnd);
connection.sendStanza(p);

参见:Smack - Getting Started,第"Reading and Writing Packets"一节。


设置后,我无法将其取出。那就是问题所在。我期望有一个这样的函数:connection.getStatus(),connection.getMode(); - emeraldhieu
嗨@Flow..我已经尝试过了..但它只显示在线用户的状态..如何获取所有离线、在线用户的状态? - BMM

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接