我刚刚尝试了一些连接WPA2企业网络的Android代码,但没有一个代码可以连接成功。我需要正确的代码来连接正确的网络。目前我使用了这个答案,但我需要一些澄清,因为这个答案是非常老的。这里我附上了一些有关连接的屏幕截图以便澄清。在这个屏幕截图中,您可以看到"身份"和"密码"两个字段。
我在Wificonfiguration中找到了企业级功能,可以设置身份和密码。
WifiConfiguration wifiConfiguration = new WifiConfiguration();
wifiConfiguration.SSID = "\"" + networkSSID + "\"";
wifiConfiguration.BSSID = Bssid;
wifiConfiguration.hiddenSSID = true;
wifiConfiguration.status = WifiConfiguration.Status.DISABLED;
wifiConfiguration.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_EAP);
wifiConfiguration.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.IEEE8021X);
wifiConfiguration.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
wifiConfiguration.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
wifiConfiguration.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.SHARED);
wifiConfiguration.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
wifiConfiguration.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
wifiConfiguration.enterpriseConfig.setIdentity(identity);
wifiConfiguration.enterpriseConfig.setPassword(password);
wifiConfiguration.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
wifiConfiguration.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
if (networkPasskey.matches("^[0-9a-fA-F]+$")) {
wifiConfiguration.wepKeys[0] = networkPasskey;
} else {
wifiConfiguration.wepKeys[0] = "\"".concat(networkPasskey).concat("\"");
}
wifiConfiguration.wepTxKeyIndex = 0;
我在Wificonfiguration中找到了企业级功能,可以设置身份和密码。
wifiConfiguration.enterpriseConfig.setIdentity(identity);
wifiConfiguration.enterpriseConfig.setPassword(password);
但是这个有什么用处呢?我们已经有了身份和密码。
if (networkPasskey.matches("^[0-9a-fA-F]+$")) {
wifiConfiguration.wepKeys[0] = networkPasskey;
} else {
wifiConfiguration.wepKeys[0] = "\"".concat(networkPasskey).concat("\"");
}
wifiConfiguration.wepTxKeyIndex = 0;
我正在使用BSSID,因为我的AP具有相同的ssid,所以我想通过使用BSSID连接正确的网络。