mWifiManager = (WifiManager)getSystemService(WIFI_SERVICE); try { WifiConfiguration wc = new WifiConfiguration(); wc.SSID = "\"ICCL\""; //AP SSID NAME wc.preSharedKey = "\"passwd\""; //AP passwd wc.hiddenSSID = true; wc.status = WifiConfiguration.Status.ENABLED; wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP); wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP); wc.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK); wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP); wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP); wc.allowedProtocols.set(WifiConfiguration.Protocol.RSN); int netId = mWifiManager.addNetwork(wc); boolean success = mWifiManager.enableNetwork(netId, false); //Connect AP if(success){ //只能說明你的密碼沒有輸錯,並且網路可用,但不一定連接上了! Toast.makeText(getApplicationContext(), "Connect ICCL AP.", Toast.LENGTH_SHORT).show(); }else{ Toast.makeText(getApplicationContext(), "Connect ICCL AP.", Toast.LENGTH_SHORT).show(); } } catch (Exception e) { Toast.makeText(getApplicationContext(), "Err", Toast.LENGTH_SHORT).show(); e.printStackTrace(); }
2012年4月19日 星期四
透過App連線AP(密碼) (1)
程式碼如下
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言