Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WifiManager reconnect returns true but does not connect

My app creates an adhoc connection if the signal is strong enough. Unfortunately Android does not allow multiple WIFI networks so I have to disconnect the current one. When the signal becomes to weak I want to reconnect to the previous one.

I store the SSID of the previous connection in a SharedPreference and then I use the following code:

 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();
         }
    }
 }

The code is working and WifiManger.reconnect(); returns true but I'm not connected to the previous network.

This is the configuration of my home network which I want to reconnect:

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
like image 859
stefan Avatar asked Nov 09 '22 12:11

stefan


1 Answers

The fault were the quotes since I already stored WifiConfiguration.SSID in my SharedPreferences this resulted in double quotes -> ""WLAN.Tele2.net""

equals("\"" + networkSSID + "\"")
like image 97
stefan Avatar answered Nov 14 '22 23:11

stefan