[Android ICS] Change wifi network proxy programmatically

5,316 views
Skip to first unread message

Francesco Pace

unread,
May 4, 2012, 8:05:09 AM5/4/12
to android-...@googlegroups.com
Hi, I'm working on Android 4.0.3 and I would to set proxy address and proxy port for a wireless network using Android SDK.
In the previous versions (2.3.3 for example) I'm able to set using Settings.System string.
With ICS I've seen that now Proxy Address and Proxy Port is specific for any Wireless network.

How can I do it?

Thanks.

Irfan Sheriff

unread,
May 4, 2012, 12:44:13 PM5/4/12
to android-...@googlegroups.com
It is not supported through the SDK.

Thanks

--
You received this message because you are subscribed to the Google Groups "android-platform" group.
To view this discussion on the web visit https://groups.google.com/d/msg/android-platform/-/UhTcFdJg7dwJ.
To post to this group, send email to android-...@googlegroups.com.
To unsubscribe from this group, send email to android-platfo...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-platform?hl=en.

Francesco Pace

unread,
May 5, 2012, 9:27:39 AM5/5/12
to android-...@googlegroups.com
Ok, thanks.
But there are some workaround for example private api to perform this operation?

Francesco Pace

unread,
May 5, 2012, 9:29:05 AM5/5/12
to android-...@googlegroups.com
Thanks.
But there are some workaround to perform this operation? For example can I use some private api?

biAji

unread,
May 8, 2012, 5:44:39 AM5/8/12
to android-...@googlegroups.com
On Sat, May 5, 2012 at 9:29 PM, Francesco Pace <pax...@gmail.com> wrote:
> Thanks.
> But there are some workaround to perform this operation? For example can I use some private api?

If you have root access, you can set environment variable using command line.



--

biAji

coolypf

unread,
Jul 24, 2012, 11:12:34 PM7/24/12
to android-...@googlegroups.com
A little modification that makes it corrent.

        WifiManager manager = (WifiManager)getSystemService(Context.WIFI_SERVICE);
        manager.asyncConnect(this, new Handler());
        if (!manager.isWifiEnabled()) return;
        List<WifiConfiguration> configurationList = manager.getConfiguredNetworks();
        WifiConfiguration configuration = null;
        int cur = manager.getConnectionInfo().getNetworkId();
        for (int i = 0; i < 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);


在 2012年7月24日星期二UTC+8下午2时38分20秒,coolypf写道:
To change Wi-Fi proxy settings on ICS, you need access to private APIs.
The following code works on my CM9 device.

        WifiManager manager = (WifiManager)getSystemService(Context.WIFI_SERVICE);
        if (!manager.isWifiEnabled()) return;
        List<WifiConfiguration> configurationList = manager.getConfiguredNetworks();
        WifiConfiguration configuration = null;
        int cur = manager.getConnectionInfo().getNetworkId();
        for (int i = 0; i < 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.setHttpProxy(new ProxyProperties("127.0.0.1", 3128, ""));
        manager.updateNetwork(config);
        manager.saveConfiguration();


在 2012年5月4日星期五UTC+8下午8时05分09秒,Francesco Pace写道:

coolypf

unread,
Nov 20, 2012, 6:48:08 PM11/20/12
to android-...@googlegroups.com
You need access to private APIs.
Check the following link if you don't know how to use Android private APIs.

https://devmaze.wordpress.com/2011/01/18/using-com-android-internal-part-2-hacking-around/

在 2012年11月20日星期二UTC+8下午8时48分27秒,Doiphode Rahul Yashwant写道:

Hi I am trying to add the above code to programatically set the proxy setting for a particular wifi config, but I am running into problem where in Eclipse shows errors for the code >> WifiConfiguration.IpAssignment.UNASSIGNED <<

any ideas on how to get this working?

please check attached screenshot. 


Doiphode Rahul Yashwant

unread,
Nov 21, 2012, 5:20:59 AM11/21/12
to android-...@googlegroups.com
thats brilliant!

thanks got it to work...

the last 2 parts of the blog were most useful:


they also have pre patched android.jar files on git


regards,

Rahul Yashwant Doiphode
PGP-ABM1 Batch Representative
Member - ENTRE | CCC | Perspectives | Confluence (Logistics) | CHAOS (Logistics) | Insight (Logistics) 

Post Graduate Programme in Agri-Business Management (Batch 2012-14)
Dorm 24, Room 15
Indian Institute of Management, Ahmedabad
Ph. No.: (079) 66326465 | 9913971468

IIM-A's PGP-ABM program was ranked 1st in the world by Eduniversal's Masters Ranking in 2011 (source)



--
You received this message because you are subscribed to the Google Groups "android-platform" group.
To view this discussion on the web visit https://groups.google.com/d/msg/android-platform/-/vr3Ut1b1MHgJ.
Reply all
Reply to author
Forward
0 new messages