我想创建一个允许用户连接到wifi网络的应用程序,但是我无法连接到网络
我目前的代码是:
WifiManager wifi = (WifiManager) getSystemService(WIFI_SERVICE);
wifi.setWifiEnabled(true);
WifiConfiguration wc = new WifiConfiguration();
wifi.startScan();
List l=wifi.getScanResults();
wc.SSID = l.get(NUMBER).SSID;
post(wc.SSID);
/*This is the bit that I think is failing, my network does not have these properties.. but I can't see how to get them from the Scan Result*/
wc.preSharedKey = "\"passw0rd123\"";
wc.hiddenSSID = false;
wc.status = WifiConfiguration.Status.ENABLED;
wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
wc.allowedGroupCiphers.set(MP);
wc.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
wc.allowedPairwiseCiphers.set(MP);
wc.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
int res = wifi.addNetwork(wc);
post("add Network returned " + res);
boolean b = wifi.enableNetwork(res, true);
post("enableNetwork returned " + b);
我认为这与设置(在我的评论之后)有关,这与我的网络配置不同,但我不知道如何从ScanResult获取这些设置.
编辑:
我还想知道它是否已正确连接.