2012年4月23日 星期一

透過App連線AP(密碼) (2)

經過上次的練習發現,Google了一下,發現對於不同的AP的設定有不同的寫法

就好比你的AP所設定的加密方式是WPA、WEP或是沒設密碼

在Android的寫法都有些不同


//初始設定
WifiConfiguration config = new WifiConfiguration();  
config.allowedAuthAlgorithms.clear();
config.allowedGroupCiphers.clear();
config.allowedKeyManagement.clear();
config.allowedPairwiseCiphers.clear();
config.allowedProtocols.clear();
config.SSID = "\"" + SSID + "\"";


//沒設定密碼(開放式網路)
config.wepKeys[0] = "";
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
config.wepTxKeyIndex = 0;

//WEP
config.preSharedKey = "\""+Password+"\"";   
config.hiddenSSID = true;    
config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.SHARED);  
config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);  
config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);  
config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40);  
config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP104);  
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);  
config.wepTxKeyIndex = 0;

//WPA
config.preSharedKey = "\""+Password+"\"";
config.hiddenSSID = true;  
config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);  
config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);              
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);              
config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);        
config.allowedProtocols.set(WifiConfiguration.Protocol.WPA);                     
config.status = WifiConfiguration.Status.ENABLED;

以下連結的作者他針對不同型式寫成了一個函式(93~136行)
參考連結:http://blog.csdn.net/cscmaker/article/details/7032277








沒有留言:

張貼留言