How to set proxy server in WebView on Lollipop 5.0

My application 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 several articles on StackOverflow showing how to do this via reflection:

  • WebView android proxy
  • Android WebView sets proxy programmatically on Android-L

Unfortunately, the methods in the first article only work with KitKat 4.4, and for Android L / 5.0 it is necessary to configure proxy settings (via System.setProperty("http.proxyHost", ...)

and System.setProperty("http.proxyPort", ...)

) that affect not only the WebView For example, the Apache HTTP client seems to pick up those parameters as well ...

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

+3
android android-5.0-lollipop android-webview


source to share


1 answer


In API> 21 lollipop, it doesn't allow setting proxy settings in webviews. The methods have been removed.

So now the only way is to set the system proxy as you mentioned, then clear the proxy in onPause

and out of onStop

your activity methods. You can clear:



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

      

Hope you find this helpful.

0


source to share







All Articles
Loading...
X
Show
Funny
Dev
Pics