gpt4 book ai didi

android - 为什么当 XMPP 连接断开时状态类型用户从不可用变为可用

转载 作者:行者123 更新时间:2023-11-30 02:33:43 25 4
gpt4 key购买 nike

关闭应用程序并停止执行ping时如何正确注销?

当我在每一行代码下面运行注销时,它运行完美,

但是如果我运行代码行:

 Presence presence = new Presence(org.jivesoftware.smack.packet.Presence.Type.unavailable);
presence.setStatus(connection.getUser() + status);
connection.sendPacket(presence);

我让用户离线/不可用。//但是连接还活着

然后我想断开连接所以我运行行代码。

connection.disconnect();//I get user online/available and connection die.

当连接中断时,我遇到了更多问题,我收到类似 ping 的消息。

11-13 21:55:02.820: D/SMACK(7399): 09:55:02 PM SENT (1385370112):  
11-13 21:55:32.820: D/SMACK(7399): 09:55:32 PM SENT (1385370112):
11-13 21:56:02.820: D/SMACK(7399): 09:56:02 PM SENT (1385370112):
11-13 21:56:32.820: D/SMACK(7399): 09:56:32 PM SENT (1385370112):
11-13 21:57:02.820: D/SMACK(7399): 09:57:02 PM SENT (1385370112):
11-13 21:57:32.820: D/SMACK(7399): 09:57:32 PM SENT (1385370112):
11-13 21:58:02.824: D/SMACK(7399): 09:58:02 PM SENT (1385370112):
11-13 21:58:32.824: D/SMACK(7399): 09:58:32 PM SENT (1385370112):
11-13 21:59:02.824: D/SMACK(7399): 09:59:02 PM SENT (1385370112):
11-13 21:59:32.824: D/SMACK(7399): 09:59:32 PM SENT (1385370112):

public void logOut(boolean unavailable, String status) {

if (isConnectionAlive() || reConnectAndAuth()) {
Presence presence = new Presence(org.jivesoftware.smack.packet.Presence.Type.unavailable);
presence.setStatus(connection.getUser() + status);
connection.sendPacket(presence);
pm = null;
connection.disconnect();
//iscNNcet();
Log.w("LogOut","LogOut");
}
}

最佳答案

我通过下一段代码解决了这个问题。

public void logOut(boolean unavailable, String status,Context orgContext) {

if (isConnectionAlive() || reConnectAndAuth(orgContext)) {
Presence presence = new Presence(org.jivesoftware.smack.packet.Presence.Type.unavailable);
presence.setStatus(connection.getUser() + status);
pm = null;

try {
connection.disconnect(presence);
} catch (Exception exception) {
exception.printStackTrace();
connection.disconnect();
}

Log.w("LogOut", "LogOut");

}
}

关于android - 为什么当 XMPP 连接断开时状态类型用户从不可用变为可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26923497/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com