android连接指定的wifi




    public WifiManager wifiManager;
    public WifiConfiguration config;
public void connectGS() {
        System.out.println("准备连接"+AP_NAME);
        config = new WifiConfiguration();  
        config.SSID = "\"" + AP_NAME + "\"";  
        config.allowedKeyManagement.set(KeyMgmt.NONE);  
        wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
        int networkId = wifiManager.addNetwork(config);  
        if(networkId != -1){  
            wifiManager.enableNetwork(networkId, true);  
            wifiManager.saveConfiguration(); 
            System.out.println("连接"+AP_NAME);
        }else {
            System.out.println("连接"+AP_NAME+",networkId = -1");

        }

你可能感兴趣的:(android连接指定的wifi)