Reputation: 4129
I am trying to create a wi-fi connection from a scan result. The only advertised capability is ESS and it is a network with no security details.
WifiConfiguration wc = new WifiConfiguration();
wc.SSID = result.SSID;
wc.BSSID = result.BSSID;
//No password. it should be an open network
wc.status = WifiConfiguration.Status.ENABLED;
wc.priority = 100000;
wc.hiddenSSID = false;
int netId = mainWifi.addNetwork(wc);
if (netId == -1)
{
showMessageDialog("Error connecting to network.");
return;
}
mainWifi.enableNetwork(netId, true);
mainWifi.setWifiEnabled(true);
I keep getting -1, which is completely unhelpful and neither the console or logcat is giving me any output on this.
Am I missing something? Is there a way to debug this problem?
Upvotes: 1
Views: 1426
Reputation: 72
WifiConfiguration wc = new WifiConfiguration();
wc.SSID = "\"" + result.SSID + "\"";
wc.BSSID = "\"" + result.BSSID + "\"";
Upvotes: 1
Reputation: 4129
The SSID must be in Quotes:
wc.SSID = "\"SSID_NAME\""; //IMP! This should be in Quotes!!
Answer comes from this question: https://stackoverflow.com/a/8818921/178931
Upvotes: 2