Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
533 views
in Technique[技术] by (71.8m points)

networking - How Android application decide if they want to use network proxy or not

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...