我正在尝试从扫描结果创建一个Wi-Fi连接。唯一公布的功能是ESS,它是一个没有安全细节的网络。
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);
我一直得-1,这完全没用,控制台或logcat都没有给我任何输出。
我错过了什么吗?有没有办法调试这个问题?
答案 0 :(得分:2)
SSID必须在引号中:
wc.SSID = "\"SSID_NAME\""; //IMP! This should be in Quotes!!
答案 1 :(得分:1)
WifiConfiguration wc = new WifiConfiguration();
wc.SSID = "\"" + result.SSID + "\"";
wc.BSSID = "\"" + result.BSSID + "\"";