配置WifiConfiguration

  1. public WifiConfiguration CreateWifiInfo(String SSID, String Password, int Type)     
  2.    {     
  3.          WifiConfiguration config = new WifiConfiguration();       
  4.           config.allowedAuthAlgorithms.clear();     
  5.           config.allowedGroupCiphers.clear();     
  6.           config.allowedKeyManagement.clear();     
  7.           config.allowedPairwiseCiphers.clear();     
  8.           config.allowedProtocols.clear();     
  9.          config.SSID = "\"" + SSID + "\"";       
  10.              
  11.          WifiConfiguration tempConfig = this.IsExsits(SSID);               
  12.          if(tempConfig != null) {      
  13.              mWifiManager.removeNetwork(tempConfig.networkId);      
  14.          }    
  15.              
  16.          if(Type == 1) //WIFICIPHER_NOPASS    
  17.          {     
  18.               config.wepKeys[0] = "";     
  19.               config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);     
  20.               config.wepTxKeyIndex = 0;     
  21.          }     
  22.          if(Type == 2) //WIFICIPHER_WEP    
  23.          {     
  24.              config.hiddenSSID = true;    
  25.              config.wepKeys[0]= "\""+Password+"\"";     
  26.              config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.SHARED);     
  27.              config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);     
  28.              config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);     
  29.              config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40);     
  30.              config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP104);     
  31.              config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);     
  32.              config.wepTxKeyIndex = 0;     
  33.          }     
  34.          if(Type == 3) //WIFICIPHER_WPA    
  35.          {     
  36.          config.preSharedKey = "\""+Password+"\"";     
  37.          config.hiddenSSID = true;       
  38.          config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);       
  39.          config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);                             
  40.          config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);                             
  41.          config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);                        
  42.          //config.allowedProtocols.set(WifiConfiguration.Protocol.WPA);      
  43.          config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);    
  44.          config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);    
  45.          config.status = WifiConfiguration.Status.ENABLED;       
  46.          }    
  47.           return config;     
  48.    }     
posted @ 2015-09-09 16:44  dongweiq  阅读(1573)  评论(0编辑  收藏  举报