gpt4 book ai didi

Android:如何防止 DHCP 续订时 Wifi 断开连接?

转载 作者:太空狗 更新时间:2023-10-29 15:00:44 28 4
gpt4 key购买 nike

我们正在自定义 Android 平台上开发软件,我们开始收到客户关于 Wifi 连接状态的投诉。似乎偶尔,他们会断开 Wifi 连接 1-2 秒,然后自动恢复。他们可以从一个小的 GUI 反馈或从 XMPP 客户端发出的断开连接/重新连接事件中注意到这一点。

经过调查,我们从adb logcat的日志中发现,每次有Wifi连接时,Wifi的状态都会从CONNECTED变为CONNECTING DHCP更新。由于我们目前的 DHCP 租用时间为 1 小时,我们的平台尝试每 29 分钟更新一次地址。这是 DHCP 更新的日志摘录:

[ 11-24 10:10:11.751  2629: 3350 D/DhcpStateMachine ]
DHCP renewal on wlan0

[ 11-24 10:10:12.351 2629: 3350 D/DhcpStateMachine ]
DHCP succeeded on wlan0

[ 11-24 10:10:12.361 2877: 2877 D/DCT ]
onReceive: action=android.net.wifi.STATE_CHANGE

[ 11-24 10:10:12.361 2877: 2877 D/DCT ]
NETWORK_STATE_CHANGED_ACTION: mIsWifiConnected=false

[ 11-24 10:10:12.361 2877: 2877 D/DCT ]
NETWORK_STATE_CHANGED_ACTION: networkInfo=NetworkInfo: type: WIFI[], state: CONNECTING/VERIFYING_POOR_LINK, reason: (unspecified), extra: "XXX", roaming: false, failover: false, isAvailable: true

[ 11-24 10:10:12.371 2877: 2877 D/DCT ]
onReceive: action=android.net.wifi.STATE_CHANGE

[ 11-24 10:10:12.371 2877: 2877 D/DCT ]
NETWORK_STATE_CHANGED_ACTION: mIsWifiConnected=false

[ 11-24 10:10:12.371 2877: 2877 D/DCT ]
NETWORK_STATE_CHANGED_ACTION: networkInfo=NetworkInfo: type: WIFI[], state: CONNECTING/CAPTIVE_PORTAL_CHECK, reason: (unspecified), extra: "XXX", roaming: false, failover: false, isAvailable: true

[ 11-24 10:10:12.381 2877: 2877 D/DCT ]
onReceive: action=android.net.wifi.STATE_CHANGE

[ 11-24 10:10:12.381 2877: 2877 D/DCT ]
NETWORK_STATE_CHANGED_ACTION: mIsWifiConnected=true

[ 11-24 10:10:12.381 2877: 2877 D/DCT ]
NETWORK_STATE_CHANGED_ACTION: networkInfo=NetworkInfo: type: WIFI[], state: CONNECTED/CONNECTED, reason: (unspecified), extra: "XXX", roaming: false, failover: false, isAvailable: true

在使用 DHCP 时,如何防止连接状态从 CONNECTED 更改为 CONNECTING?我可以在某处更改设置以更改此行为吗?

最佳答案

我认为 DISCONNECTING 无法真正避免。处理此问题的唯一方法是忽略 Wifi 更改状态上的 DISCONNECTING 状态并使用 isConnectedOrConnecting来自 Network 而不是 isConnected 的方法以验证我们是否已连接。

关于Android:如何防止 DHCP 续订时 Wifi 断开连接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27108126/

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