您好我正在尝试使用wifimanager api将我的应用连接到特定的接入点。 现在我有一个我所在区域的所有接入点的列表,从这个列表中我将它们存储在一个数组中并选择要连接的接入点。 但在这个阶段是剂量不连接。 有人能帮我吗 。
(这是一个我正在尝试连接的开放式网络。) 这是我的代码:
public void WifiConfiguration(){
try {
ScanResult networkData = getIntent().getParcelableExtra("networkData");
WifiManager wifiManager = (WifiManager)getApplicationContext().getSystemService(Context.WIFI_SERVICE);
String networkPassWord = "";
WifiConfiguration conf = new WifiConfiguration();
conf.SSID = "\"" + networkData.SSID + "\"";
conf.BSSID = "\"" + networkData.BSSID + "\"";
conf.hiddenSSID = true;
conf.wepKeys[0] = "\"" + networkPassWord + "\"";
conf.wepTxKeyIndex = 0;
conf.status = WifiConfiguration.Status.ENABLED;
conf.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
conf.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
conf.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
conf.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
conf.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
conf.preSharedKey = "\""+ networkPassWord +"\"";
//conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
Log.d(TAG, "Initialising WIFI Manager");
int id = wifiManager.addNetwork(conf);
Log.d(TAG, "conf.SSID: "+conf.SSID);
Log.d(TAG, "id: "+id);
wifiManager.disconnect();
wifiManager.enableNetwork(id, true);
wifiManager.reconnect();
Log.d(TAG, "Should be connected....");
} catch (Exception e) {
Log.d(TAG, e.toString());
}
}
答案 0 :(得分:0)
conf.SSID = "\"" + networkData.SSID + "\"";
conf.BSSID = "\"" + networkData.BSSID + "\"";
BSSID不需要用双引号括起来,只需要用SSID括起来。