Android 连接加密网络

WifiManager wifiManager = (WifiManager)getSystemService(Context.WIFI_SERVICE);
        boolean bRet1 = wifiManager.setWifiEnabled(true);
        
        //add network
        if (wifiManager.startScan())    //扫描可用的无线网络
        {
        List<ScanResult> scanResultList = wifiManager.getScanResults();
        for (int i = 0; i < scanResultList.size(); i++)
        {
            ScanResult scanRet = scanResultList.get(i);
            if (scanRet.SSID.equalsIgnoreCase("TEST"))   //找到 TEST
            {
                WifiConfiguration config = new WifiConfiguration();

                config.SSID = "\"" + scanRet.SSID + "\"";
                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;
                 
                int netID = wifiManager.addNetwork(config);
                Log.d("WifiPreference", "add Network returned " + netID );
                boolean bRet = wifiManager.enableNetwork(netID, true);
                Log.d("WifiPreference", "enableNetwork returned " + bRet );
            }
        }
        }


你可能感兴趣的:(android,加密,网络,service,NetWork)