Settings.Secure.HTTP_PROXY deprecated in ICS but no information on replacement

后端 未结 2 553
失恋的感觉
失恋的感觉 2021-02-13 16:24

The Android developer docs say the following about Settings.Secure.HTTP_PROXY:

Host name and port for global http proxy. Uses \':\' seperator

相关标签:
2条回答
  • 2021-02-13 16:46

    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.

    0 讨论(0)
  • 2021-02-13 17:07

    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.

    0 讨论(0)
提交回复
热议问题