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

时间:2014-11-24 15:19:41

标签: android android-wifi dhcp

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

经过调查,我们从登录adb logcat中发现,每次有DHCP续订时,Wifi都会将其状态从CONNECTED更改为CONNECTING。由于我们目前的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?我可以在某处更改设置以更改此行为吗?

1 个答案:

答案 0 :(得分:0)

我认为DISCONNECTING不能真正避免。解决此问题的唯一方法是忽略Wifi更改状态下的DISCONNECTING状态,并使用Network而不是isConnectedOrConnecting中的isConnected方法验证我们是否是否连接。