title: How can I set ProxySettings and ProxyProperties on Android Wi-Fi connection using Java?
body: <p>How can I set ProxySettings and ProxyProperties on an Android Wi-Fi connection using Java (programatically)?</p>
  
  <p>As ipAssignment, linkProperties, ProxySettings and ProxyProperties are hidden fields within WifiConfiguration on Android 3.1 and up, I need to be able to enum the class and use the fields.</p>
  
  <p>Following the code sample using the link below, I can set a static IP address, gateway and DNS for a particular Wi-Fi connection, but I also need to set Wificonfiguration.ProxySettings.STATIC and ProxyProperties </p>
  
  <p>See Stack Overflow question <em><a href="https://stackoverflow.com/questions/10278461">How to configue a static IP address, netmask, gateway programmatically on Android 3.x or 4.x</a></em>.</p>
  
  <p>For example,</p>
  
  <pre><code>WifiConfiguration config = new WifiConfiguration(configuration);
  config.ipAssignment = WifiConfiguration.IpAssignment.UNASSIGNED;
  config.proxySettings = WifiConfiguration.ProxySettings.STATIC;
  config.linkProperties.setHttpProxy(new ProxyProperties("127.0.0.1", 3128, ""));
  </code></pre>
  
  <p>Looking for something like:</p>
  
  <pre><code>setProxySettings("STATIC", wifiConf);
  setProxyProperties("proxyserver.mine.com.au", 8080, ""); // Set Proxy server and port.
  wifiManager.updateNetwork(wifiConf); //apply the setting
  </code></pre>
  
  <p>Using the following code from coolypf .ipAssignment .ProxySettings and linkProperties are hidden...</p>
  
  <pre><code>    WifiManager manager = (WifiManager)getSystemService(Context.WIFI_SERVICE);
  manager.asyncConnect(this, new Handler());
  if (!manager.isWifiEnabled()) return;
      List&lt;WifiConfiguration&gt; configurationList = manager.getConfiguredNetworks();
      WifiConfiguration configuration = null;
      int cur = manager.getConnectionInfo().getNetworkId();
      for (int i = 0; i &lt; configurationList.size(); ++i)
      {
          WifiConfiguration wifiConfiguration = configurationList.get(i);
          if (wifiConfiguration.networkId == cur)
          configuration = wifiConfiguration;
      }
      if (configuration == null) return;
      WifiConfiguration config = new WifiConfiguration(configuration);
      config.ipAssignment = WifiConfiguration.IpAssignment.UNASSIGNED;
      config.proxySettings = WifiConfiguration.ProxySettings.STATIC;
  
      config.linkProperties.clear();
  
      config.linkProperties.setHttpProxy(new ProxyProperties("127.0.0.1", 3128, ""));
  
      manager.saveNetwork(config);
  </code></pre>