In my App I have a Network Selection Screen, this shows all visible networks - including Configured Hidden SSID's.
However when a user selects a visible network that is not a Hidden SSID, and associates to it using the following code.
public boolean associate(ScanResultWrapper scanResult){
WifiConfiguration wc = getWifiConfiguration(scanResult.scanResult);
int id = -1;
if (wc == null ) {
wc = new WifiConfiguration();
wc.SSID = "\"" + scanResult.SSID + "\"";
wc.BSSID = scanResult.scanResult.BSSID;
wc.status = WifiConfiguration.Status.ENABLED;
wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
wc.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
wc.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
wc.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
id = mWifiManager.addNetwork(wc);
if (!mWifiManager.saveConfiguration()){
return false;
}
} else{
id = wc.networkId;
}
boolean result;
try {
result = mWifiManager.enableNetwork(id, true);
return result;
} catch (Throwable t) {
t.printStackTrace();
return false;
}
}
So the method to associate to a network shown here http://developer.android.com/reference/android/net/wifi/WifiManager.html#enableNetwork(int, boolean)
mWifiManager.enableNetwork(id, true);
Disables all other configurations. This is Okay for non-Hidden SSID's, yet this means that my Hidden SSID configuration is disabled, and is no longer included in the Scan results. Meaning that if a user is on a Hidden Network and joins another network, they can not go back to join their Hidden Network unless they launch their device Wifi Settings.
I have found that the above method for changing Wifi Network Programmatically must be different from the method used by the device Wifi Settings. For if you Associate Programmatically then go to the Wifi Settings screen you will see that all other Configured Networks have been set to "Disabled". However, If you Associate to a network from the Device Wifi Settings Screen all other Wifi Configurations stay as "Saved".
Does anyone have an alternate method for programmatically associating to a network which retains Hidden SSID configurations without Disabling them?
Thanks, this is a real pain.