尝试以编程方式从 Android 连接到我的无线网络。
安全类型是WPA2,加密AES。
这没有按预期工作:
private WifiConfiguration saveWepConfig(String password, String networkSSID) {
WifiConfiguration conf = new WifiConfiguration();
conf.SSID = "\"" + networkSSID + "\"";
// conf.wepKeys[0] = "\"" + password + "\"";
conf.preSharedKey = "\"" + password + "\"";
conf.wepTxKeyIndex = 0;
conf.hiddenSSID = true;
conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
conf.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40);
return conf;
}
我必须在这里加密密码吗?只保存连接,不连接。
啊...我发布问题后立即找到了解决方案:
WifiConfiguration conf = new WifiConfiguration();
conf.SSID = "\"" + networkSSID + "\"";
conf.preSharedKey = "\"" + password + "\"";
// conf.hiddenSSID = true;
// conf.wepTxKeyIndex = 0;
// conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
// conf.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40);
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);
它对我有用。谢谢。
我是一名优秀的程序员,十分优秀!