gpt4 book ai didi

java - Android WifiConfiguration 显示 ID 为 -1。如何修复才能识别 SSID?

转载 作者:太空宇宙 更新时间:2023-11-04 15:06:24 27 4
gpt4 key购买 nike

String networkSSID = "networkName";
String networkPassword = "networkPassword";

WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);

if (!wm.isWifiEnabled()) {

if (wm.getWifiState() != WifiManager.WIFI_STATE_ENABLING) {

wm.setWifiEnabled(true);
}
}

WifiConfiguration wifiConfig = new WifiConfiguration();

wifiConfig.allowedAuthAlgorithms.clear();
wifiConfig.allowedGroupCiphers.clear();
wifiConfig.allowedKeyManagement.clear();
wifiConfig.allowedPairwiseCiphers.clear();
wifiConfig.allowedProtocols.clear();

wifiConfig.SSID = "\"" + networkSSID + "\"";
wifiConfig.priority = 40;
wifiConfig.hiddenSSID = true;

wifiConfig.status = WifiConfiguration.Status.ENABLED;

wifiConfig.wepKeys[0] = "\"" + networkPassword + "\"";
wifiConfig.wepTxKeyIndex = 0;
wifiConfig.preSharedKey = "\"" + networkPassword + "\"";

wifiConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
wifiConfig.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.SHARED);
wifiConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
wifiConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
wifiConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40);
wifiConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP104);

int netId = wm.addNetwork(wifiConfig);

wm.disconnect();
wm.enableNetwork(netId, false);
wm.reconnect();
<小时/>

这是我编写的用于使用 SSID 和密码连接到 WEP 无线的代码,但是当我调试代码时,它显示 WifiConfiguration 的 ID 为 -1。它导致netID的值为-1,并且没有无线连接。请帮忙!谢谢。

最佳答案

我很确定配置不正确,或者只是尝试设置 BSSID:

wc.BSSID = yourBSSID;

因为你有一个隐藏的网络。您可以通过网络扫描获取它,其中 SSID 没有值。

关于java - Android WifiConfiguration 显示 ID 为 -1。如何修复才能识别 SSID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21937887/

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