gpt4 book ai didi

android - 如何忘记现在不可用的 wifi?

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:10:34 29 4
gpt4 key购买 nike

我想用这个代码示例忘记 wifi 网络,但它不能忘记不在范围内的 wifi。

private void removeNetwork(WifiManager wifiManager, WifiConfiguration wc) {
if (!wifiManager.isWifiEnabled()) enableWifi();
int id = wifiManager.addNetwork(wc);
wifiManager.enableNetwork(id, true);
wifiManager.removeNetwork(id);
wifiManager.saveConfiguration();
}

如何删除网络?

UPD1:

我说的是我自己添加的WIFI信息。

private void addNetwork(WifiManager wifiManager, WifiConfiguration wc) {
if (!wifiManager.isWifiEnabled()) enableWifi();
int id = wifiManager.addNetwork(wc);
wifiManager.disconnect();
wifiManager.enableNetwork(id, true);
wifiManager.reconnect();
wifiManager.saveConfiguration();
}

最佳答案

我测试了这个代码示例并且代码运行良好,你的代码实现有问题。

这取决于 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);
}
}

关于android - 如何忘记现在不可用的 wifi?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53846226/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com