如果信号足够强,我的应用程序会创建临时连接。不幸的是,Android 不允许多个 WIFI 网络,所以我必须断开当前的连接。当信号变弱时,我想重新连接到前一个。
我将之前连接的 SSID 存储在 SharedPreference 中,然后使用以下代码:
for (WifiConfiguration i : list) {
if (i.SSID != null && i.SSID.equals("\"" + networkSSID + "\"")) {
wifiManager.disconnect();
wifiManager.enableNetwork(i.networkId, true);
boolean success = wifiManager.reconnect();
if (!success) {
wifiManager.reassociate();
}
}
}
代码正常运行,WifiManger.reconnect();
返回 true 但我没有连接到之前的网络。
这是我要重新连接的家庭网络的配置:
ID: 10 SSID: ""WLAN.Tele2.net"" BSSID: null FQDN: null REALM: null PRIO: 0
KeyMgmt: NONE Protocols: WPA RSN
AuthAlgorithms:
PairwiseCiphers: TKIP CCMP
GroupCiphers: WEP40 WEP104 TKIP CCMP
PSK:
Enterprise config:
password NULL
subject_match NULL
engine 0
client_cert NULL
ca_cert NULL
anonymous_identity NULL
phase1 NULL
identity NULL
key_id NULL
engine_id NULL
phase2 NULL
sim_slot_id NULL
eap NULL
IP config:
IP assignment: DHCP
Proxy settings: NONE
autoJoinBSSID=any
triggeredLow: 0 triggeredBad: 0 triggeredNotHigh: 0
ticksLow: 0 ticksBad: 0 ticksNotHigh: 0
triggeredJoin: 0
autoJoinBailedDueToLowRssi: false
autoJoinUseAggressiveJoinAttemptThreshold: 0
最佳答案
问题出在引号上,因为我已经将 WifiConfiguration.SSID 存储在我的 SharedPreferences 中,这导致了双引号 -> ""WLAN.Tele2.net""
equals("\"" + networkSSID + "\"")
关于android - WifiManager 重新连接返回 true 但未连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30457886/