WIFI连接

private WifiConfiguration createWifiInfo(ScanResult scanResult) {
		
        WifiConfiguration config = new WifiConfiguration();
        config.allowedAuthAlgorithms.clear();
        config.allowedGroupCiphers.clear();
        config.allowedKeyManagement.clear();
        config.allowedPairwiseCiphers.clear();
        config.allowedProtocols.clear();
        config.SSID = "\"" + scanResult.SSID + "\"";
        
        config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
        
        return config;
    }

上面的是无密码连接。


//连接到指定的网络
				WifiConfiguration wifiInfo = createWifiInfo(myWifi.get(which));
				if(wifiInfo != null){
					int netId = wifiManager.addNetwork(wifiInfo);
					wifiManager.enableNetwork(netId, true);
				}


你可能感兴趣的:(WIFI连接)