2012-01-11 74 views
0

我在我的android應用程序上使用HttpClient。某些用戶可以在他的設備上配置系統代理。我如何獲取信息? 從這個answer我知道你可以這樣做:獲取有關係統代理的信息

DefaultHttpClient httpclient = new DefaultHttpClient(); 

HttpHost proxy = new HttpHost("someproxy", 8080); 
httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); 

的問題是,我不知道在哪裏找到的代理和端口的主機名。

回答

0

試試這個:

DefaultHttpClient httpclient = new DefaultHttpClient(); 

String proxyString = Settings.Secure.getString(getApplicationContext().getContentResolver(), Settings.Secure.HTTP_PROXY); 

if (proxyString != null) 
{ 
    String proxyAddress = proxyString.split(":")[0]; 
    int proxyPort = Integer.parseInt(proxyString.split(":")[1]); 
    HttpHost proxy = new HttpHost(proxyAddress, proxyPort); 

    httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); 
} 

我沒有測試過。找到here