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

好久不见. 提交于 2019-12-29 01:29:30

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!