1

我是安卓新手。我想要做的是搜索可用的网络,然后单击特定的网络会出现一个自定义对话框,用于输入密码,因为它在任何 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();
4

0 回答 0