我无法在已建立的 SSID 上连接 Android,我尝试 WifiConfiguration 但不成功,我的 ssid 已打开(无密码)。
在 Android UI 中我可以连接,但在代码上我不能。
有人帮我吗?
保护你。
编辑:
我的代码:
String networkSSID = "DL63.0.0.0.1";
String networkPass = "";
WifiConfiguration conf = new WifiConfiguration();
conf.SSID = "\"" + networkSSID + "\"";
// conf.wepKeys[0] = "\"" + networkPass + "\"";
// conf.wepTxKeyIndex = 0;
conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
// conf.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40);
WifiManager wifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
wifiManager.addNetwork(conf);
List<WifiConfiguration> list = wifiManager.getConfiguredNetworks();
for (WifiConfiguration i : list) {
if (i.SSID != null && i.SSID.equals("\"" + networkSSID + "\"")) {
wifiManager.disconnect();
wifiManager.enableNetwork(i.networkId, true);
wifiManager.reconnect();
Toast.makeText(this, "SSID: "+wifiManager.getConnectionInfo().getSSID(), Toast.LENGTH_SHORT).show();
break;
}
}
status.setText("SSID: "+wifiManager.getConnectionInfo().getSSID());