我想连接到WifiManager.getScanResults()结果中信号最强的wifi热点。但不知怎的,即使boolean b
显示为真,我也无法启用我的设备访问网络。
wc.SSID = "\".xxxxx\"";//result from the getScanResults()
wc.preSharedKey = "\"abcdefg111\"";
wc.hiddenSSID = true;
wc.status = WifiConfiguration.Status.ENABLED;
wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
wc.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
wc.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
int res = wifi.addNetwork(wc);
Log.d("WifiPreference", "add Network returned " + res );
boolean b=false;
b= wifi.enableNetwork(res, true);
Log.d("WifiPreference", "enableNetwork returned " + b );