【发布时间】:2019-05-31 07:22:02
【问题描述】:
我像这样在我的应用程序中以编程方式连接 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断开连接时,用户不输入密码就无法再次连接?如果可能的话,我怎样才能以编程方式做到这一点?
【问题讨论】:
-
我认为您需要找出密码保存在 android 中的 wifi 连接位置,然后使用您的程序清除它。
标签: java android wifi wifimanager