我想通过编写一个简单的Android应用程序连接到我的WIFI。它启用了wifi。但是当我在手机的设置中看到该n / w时,我收到身份验证错误。 我的代码是
WifiConfiguration wc = new WifiConfiguration();
wc.SSID = "\"Network_SSID\"";
wc.hiddenSSID = true;
wc.status = WifiConfiguration.Status.DISABLED;
wc.priority = 40;
wc.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
wc.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
wc.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
wc.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
wc.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.SHARED);
wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40);
wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP104);
wc.wepKeys[0] = "\"8447657855\""; //This is the WEP Password
wc.wepTxKeyIndex = 0;
答案 0 :(得分:0)
if (Type == 1) // WIFICIPHER_NOPASS
{
config.hiddenSSID = true;
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
}
if (Type == 2) // WIFICIPHER_WEP
{
config.hiddenSSID = true;
config.wepKeys[0] = "\"" + Password + "\"";
config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40);
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
config.wepTxKeyIndex = 0;
}
if (Type == 3) // WIFICIPHER_WPA
{
config.preSharedKey = "\"" + Password + "\"";
config.hiddenSSID = true;
}