The Android developer docs say the following about Settings.Secure.HTTP_PROXY
:
Host name and port for global http proxy. Uses ':' seperator for between host and port TODO - deprecate in favor of global_http_proxy_host, etc
But there is not any information about global_http_proxy_host
. Now I always get null
when trying to read Settings.Secure.HTTP_PROXY
.
Settings.Secure.HTTP_PROXY
was working properly in all releases before ICS.
You can use Java Reflection to set the global proxy tested on ICS.
UPDATED CODE
Activity activity = this;
private void setProxtAndPortOnICS(String porxyServer2, int port2)
{
try
{
Class jwcjb = Class.forName("android.webkit.JWebCoreJavaBridge");
Class params[] = new Class[1];
params[0] = Class.forName("android.net.ProxyProperties");
Method updateProxyInstance = jwcjb.getDeclaredMethod("updateProxy", params);
Class wv = Class.forName("android.webkit.WebView");
Field mWebViewCoreField = wv.getDeclaredField("mWebViewCore");
Object mWebViewCoreFieldIntance = getFieldValueSafely(mWebViewCoreField, oauthPage);
Class wvc = Class.forName("android.webkit.WebViewCore");
Field mBrowserFrameField = wvc.getDeclaredField("mBrowserFrame");
Object mBrowserFrame = getFieldValueSafely(mBrowserFrameField, mWebViewCoreFieldIntance);
Class bf = Class.forName("android.webkit.BrowserFrame");
Field sJavaBridgeField = bf.getDeclaredField("sJavaBridge");
Object sJavaBridge = getFieldValueSafely(sJavaBridgeField, mBrowserFrame);
Class ppclass = Class.forName("android.net.ProxyProperties");
Class pparams[] = new Class[3];
pparams[0] = String.class;
pparams[1] = int.class;
pparams[2] = String.class;
Constructor ppcont = ppclass.getConstructor(pparams);
updateProxyInstance.invoke(sJavaBridge, ppcont.newInstance("my.proxy.com", 1234, null));
}
catch (Exception ex)
{
}
}
private Object getFieldValueSafely(Field field, Object classInstance) throws IllegalArgumentException, IllegalAccessException {
boolean oldAccessibleValue = field.isAccessible();
field.setAccessible(true);
Object result = field.get(classInstance);
field.setAccessible(oldAccessibleValue);
return result;
}
NOW you can filter out the urls using proxy server.
OR look at this blog this is in Chinese but you can read the code it is fairly easy to understand.
I'm just going by what the documentation says, but it reads to me that Settings.Secure.HTTP_PROXY
isn't currently deprecated. The (sloppy) note in the documentation was just a developer's note that this is something the Android team may consider doing in the future.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With