我通过编程方式在我的应用中以这种方式连接wifi
private void WPA(String networkSSID, String networkPass, WifiManager wifiManager, String command) {
WifiConfiguration wc = new WifiConfiguration();
wc.SSID = "\"" + networkSSID + "\"";
wc.preSharedKey = "\"" + networkPass + "\"";
wc.status = WifiConfiguration.Status.ENABLED;
wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
wc.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
wc.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
if (command.equals(ADD)) {
addNetwork(wifiManager, wc);
} else if (command.equals(REMOVE)) {
removeNetwork(wifiManager, wc);
}
}
private void addNetwork(WifiManager wifiManager, WifiConfiguration wc) {
if (!wifiManager.isWifiEnabled()) enableWifi();
int id = wifiManager.addNetwork(wc);
if (id > -1) {
wifiManager.disconnect();
wifiManager.enableNetwork(id, true);
wifiManager.reconnect();
wifiManager.saveConfiguration();
}
}
我想知道在Android中是否可以不保存密码而连接wifi,当wifi断开连接时,用户如果不输入密码就无法再次连接?如果有可能,我该如何以编程方式做到这一点?
感谢进阶!