连接到特定接入点android
问题描述:
嗨,我试图将我的应用程序连接到使用wifimanager API的特定接入点。 现在我有我的区域中的所有接入点的列表,从这个列表中我将它们存储在一个数组中,并选择要连接到哪个接入点。 但在这个阶段是剂量不连接。 有人可以帮助我。连接到特定接入点android
(这是一个开放的网络我试图连接到。) 这里是我的代码:
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());
}
}
答
conf.SSID = "\"" + networkData.SSID + "\"";
conf.BSSID = "\"" + networkData.BSSID + "\"";
的BSSID不存在需要被双引号括起来,只有SSID。
当你测试连接状态? – atok
我正在查看网络上的用户数量,因此没有任何应用程序,因此该应用程序未进行连接 – user3292394
我自己收到答案。 谢谢你的所有帮助。 – user3292394