我是Android新手。我想要做的是搜索可用的网络,然后点击特定的网络自定义对话框将在任何Android设备中输入密码。现在问题是Wifi被记住,然后禁用它在执行以下代码时没有连接。下面是我单击所需安全网络时执行的代码。请帮我解决这个问题
password = text.getText().toString().trim();
if(!password.equals(""))
{
wc.SSID = "\""+signal+"\""; //IMP! This should be in Quotes!!
wc.hiddenSSID = true;
System.out
.println("Oon click to action"+wc.SSID);
wc.status = WifiConfiguration.Status.ENABLED;
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.preSharedKey = "\"password\"";
// wc.wepKeys[0] = "\"password\""; //This is the WEP Password
wc.wepTxKeyIndex = 0;
int res = wifi.addNetwork(wc);
Log.d("WifiPreference", "add Network returned " + res );
boolean es = wifi.saveConfiguration();
Log.d("WifiPreference", "saveConfiguration returned " + es );
wifi.disconnect();
boolean b = wifi.enableNetwork(res, false);
wifi.reconnect();