如何Android应用程序决定是否要使用网络代理或不要使、或不、应用程序、网络

2023-09-13 01:47:31 作者:回忆散了让我拿什么保留

我一直在跑带wifi代理设置在摩托罗拉Xoom一些测试与Android 3.2。因此,首先,这是一个很大的进步相比2.x版本。现在,如果你设置代理,大多数应用程序会自动得到它(在2.x中,只有内置的浏览器使用它)。所以,我想的东西像雅虎财经,彭博社等,他们都将通过代理的罚款。我不明白的是有些浏览器如Firefox,歌剧,不会通过代理服务器。任何想法,他们是如何做到这一点。基本上在我的应用程序,我怎么能决定,如果我想使用代理服务器或尝试直接连接。根据我的测试,如果我们没有做什么特别的,默认是使用代理服务器。那么,做我需要做的,让喜欢火狐/歌剧我的应用程序绕过代理?

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?

谢谢!

推荐答案

在设备与API版本> = 11(的Andr​​oid 3.1及更高版本)的答案就在这里:

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

Android's代理混乱的文档资源

您可以简单地调用从的ProxySelector类的getDefault()方法,并得到默认的Andr​​oid实现这个ProxySelector了。

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());
}

我认为,一些Android应用程序(你说Opera和Firefox)根本就不做检查,但实现了一些本地的代理处理不关心的系统是如何工作的。

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.