This is killing me, and any help would be greatly appreciated.
I want to connect to an open network using a wifi manager. The problem I am facing is that the code claims that the connection to any network is even non-existent. Below is all the code that is launched and called from the SSID of the network. No matter which string you pass to it as the SSID of the network, even if such a network does not exist in any form or form, enableNetwork claims return true, which, in my opinion, means that it is connected to the network.
I need to do to make sure that I have a connection. Therefore, if I pass in a network SSID that does not exist (for example, it is out of range), the API should return a failure when trying to connect.
Any ideas / hints / suggestions are welcome.
public boolean conto (String network){
WifiConfiguration wifiConfiguration = new WifiConfiguration();
wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
List<WifiConfiguration> configs = null;
int inetId = -1;
configs = wifi.getConfiguredNetworks();
for (WifiConfiguration config : configs) {
wifi.removeNetwork(config.networkId);
Log.d("********", "Removed Network: SSID=[" + config.SSID + "] and ID=[" + config.networkId + "]");
}
wifiConfiguration.SSID = "\"" + network + "\"";
wifiConfiguration.hiddenSSID = false;
inetId = wifi.addNetwork(wifiConfiguration);
if(inetId < 0) {
Log.d("********", "Could Not Add Network......... [" + wifiConfiguration.SSID + "]");
}
else {
Log.d("********", "Added Network......... [" + wifiConfiguration.SSID + "]");
Log.d("********", " +++++++++++++++++++++++++ This is what I have in Config File");
configs = wifi.getConfiguredNetworks();
for (WifiConfiguration config : configs) {
Log.d("********", "In the Config file after add, SSID=[" + config.SSID + "], ID=[" + config.networkId + "]");
}
boolean successConnected = wifi.enableNetwork(inetId, true);
if(successConnected) {
Log.d("********", "Connected to......... [" + inetId + "]");
}
else {
Log.d("********", "Could Not Connect to......... [" + inetId + "]");
}
}
return false;
}
source
share