问题
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!
回答1:
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.
来源:https://stackoverflow.com/questions/9544582/how-android-application-decide-if-they-want-to-use-network-proxy-or-not