1

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?

Tjaart
  • 3,912
  • 2
  • 37
  • 61

2 Answers2

2

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

Community
  • 1
  • 1
Tjaart
  • 3,912
  • 2
  • 37
  • 61
1
WifiConfiguration wc = new WifiConfiguration();
    wc.SSID = "\"" + result.SSID + "\"";
    wc.BSSID = "\"" + result.BSSID + "\"";
SteveLin
  • 72
  • 3