2

I have been running some testing with wifi proxy settings on a Motorola Xoom with Android 3.2. So first of all, it is a big step forward comparing to 2.x releases. now if you set proxy, most of the apps automatically get it (in 2.x, only builtin browser uses it). So I tried things like yahoo finance, bloomberg, etc. and they all going through proxy fine. What I don't get is some browsers like firefox, Opera, will not go through proxy. Any idea how they did that. Basically in my app, how can I decide if I want to use proxy or try to connect directly. Based on my testing, if we don't do anything special, the default is using proxy. So what do I need to do to allow my app bypass proxy like Firefox/Opera?

Thanks!

Safecoder
  • 1,035
  • 2
  • 17
  • 32

1 Answers1

7

On devices with API version >=11 (Android 3.1 and greater) the answer is here:

Android's proxy confusing documentation resources

You can simply call the getDefault() method from ProxySelector class and get the default Android implementation of the ProxySelector.

ProxySelector defaultProxySelector = ProxySelector.getDefault();
Proxy proxy = null;
List<Proxy> proxyList = defaultProxySelector.select(uri);
if (proxyList.size() > 0)
{
  proxy = proxyList.get(0);
  Log.d(TAG, "Current Proxy Configuration: " + proxy.toString());
}

I think that some Android applications (you said Opera and Firefox) simply doesn't do this check but implements some native proxy handling not caring of how the system work.

Community
  • 1
  • 1
lechuckcaptain
  • 1,032
  • 1
  • 9
  • 25
  • Thanks, LeChuck. But based on my testing, I don't need to do anything like what you said in my app. I just do a basic HttpClient Get, I can see it is going through proxy on my Xoom. So I think by default, all net traffic goes through proxy in honeycomb and ICS if you are using the built-in networking stack. This is the right thing to do in general because you don't want each app have to set proxy by itself. However in my specic app, I do want to "bypass" the proxy and try to connect directly. I am wondering if there are any settings that allow me to do that. Any idea? – Safecoder Mar 03 '12 at 19:39
  • try to avoid using HttpClient, as suggested [here](http://android-developers.blogspot.com/2011/09/androids-http-clients.html) and explained [here](http://www.android-proxy.com/2011/11/may-force-be-with-you-use.html) (at least for the proxy details). It's seems that it's not supported by the Android team. The HttpURLConnection class request the developer to explicitily specify the the proxy when needed. – lechuckcaptain Mar 04 '12 at 16:31
  • I saw on your blog that you released a proxy setting app for kindle fire. Does it work well? I actually returned my kindle fire a couple of weeks ago because I can't set proxy. If it works, I may consider going back and buy one. :-) – Safecoder Mar 08 '12 at 04:20
  • I released the app in the Amazon Appstore. The process review for the Kindle Fire is still on evaluation. I'll post updates on the blog. Stay tuned. – lechuckcaptain Mar 08 '12 at 09:55
  • But it shows up on their website. So I still can't download it? How long does it take for their evalution process. http://www.amazon.com/LeChuck-Software-Proxy-Settings/dp/B007D3TMK6/ref=sr_1_7?s=mobile-apps&ie=UTF8&qid=1331256853&sr=1-7 – Safecoder Mar 09 '12 at 01:36
  • I think that you can download it on your phone, not on Kindle Fire (at least is what Amazon said to me). – lechuckcaptain Mar 09 '12 at 10:12
  • I thought ProxySelector is only for mobile networks. Does it also work for wifi on Kindle Fire? I remember I tried on my old HTC hero sometime back, it only works for mobile, but not for wifi. – Safecoder Mar 10 '12 at 01:39
  • ProxySelector is the main and the only entry point to get the proxy settings on an Android device. The only problem is that for devices with API version < 11 it seems to not working properly. This is the reason why I already asked to some googlers to explain how to solve the problem. – lechuckcaptain Mar 10 '12 at 10:14
  • I just posted a question on proxy setting for ICS. I think your Proxy settings is using the same hidden UI. If you can comment on it, that would be great! here is the link http://stackoverflow.com/questions/10559370/how-to-set-system-wide-proxy-in-ics – Safecoder May 11 '12 at 22:26