码迷,mamicode.com
首页 > 其他好文 > 详细

配置WifiConfiguration

时间:2015-09-09 17:32:47      阅读:610      评论:0      收藏:0      [点我收藏+]

标签:

  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.    }     

配置WifiConfiguration

标签:

原文地址:http://www.cnblogs.com/dongweiq/p/4795201.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!