3

My app has a WebView and I want to configure it to use a proxy. Apparently Android doesn't have an API that I can use to achieve this but I found some a couple of articles on StackOverflow showing how to do it via reflection:

Unfortunately the methods in the first article only work up to KitKat 4.4 and the Android L/5.0 way of doing it requires setting the application-wide proxy settings (via System.setProperty("http.proxyHost", ...) and System.setProperty("http.proxyPort", ...) which affects more than just the WebView. For example, the Apache HTTP client seems to pick up these settings too.

Is there a way to set proxy settings just for WebViews without affecting other components of the app?

Community
  • 1
  • 1
Mike Laren
  • 8,028
  • 17
  • 51
  • 70

1 Answers1

0

In API>21 lollipop, it does not allow setting proxy settings in webviews. The methods have been removed.

So the only way now is to set system wide proxy as you mentioned, then clear the proxy on onPause and onStop methods of your activity. The clear can be done by:

System.clearProperty("http.proxyHost");
System.clearProperty("http.proxyPort");

Hope you find this helpful.

friedemann_bach
  • 1,418
  • 14
  • 29