Android的WifiConfiguration显示-1 ID。我怎样才能解决它的SSID被认可? [英] Android WifiConfiguration shows -1 for ID. How can I fix it for SSID to be recognized?
本文介绍了Android的WifiConfiguration显示-1 ID。我怎样才能解决它的SSID被认可?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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();
这是code,我写的连接到无线与SSID和WEP密码,但是当我调试code,它显示ID为WifiConfiguration为-1。它导致其值-1,NETID,并有无线没有任何联系。请帮忙!谢谢。
This is the code that I write to connect to wireless for WEP with SSID and password, but when I debug the code, it shows ID for WifiConfiguration is -1. It leads to netID having the value of -1, and there is no connection to wireless. Please help! Thanks.
推荐答案
我是pretty确保配置不正确或只是尝试还设置了 BSSID
:
I'm pretty sure the configuration is not correct or simply try to set also the BSSID
:
wc.BSSID = yourBSSID;
因为你已经一个隐藏的网络。您可以从网络扫描,其中SSID是没有价值的获得。
cause you've an hidden network. You can obtain it from a network scan where the SSID has no value.
这篇关于Android的WifiConfiguration显示-1 ID。我怎样才能解决它的SSID被认可?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文