Android_webview设置代理的方法

在网上特别是中文社区搜索android webview proxy一出来大部分文章的作法都是类似这个:

https://www.jianshu.com/p/d02e8818a72e

但实测中发现,不管我SDK版本降到多低,这些方法通通失效,最后自己跟着官方文档一步一步来做:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
private void setProxy() {
ProxyConfig proxyConfig = new ProxyConfig.Builder()
.addProxyRule("http://192.168.1.12:1082")
.build();
Executor executor = new Executor() {
@Override
public void execute(Runnable command) {
}
};
Runnable listener = new Runnable() {
@Override
public void run() {
}
};
if (WebViewFeature.isFeatureSupported(WebViewFeature.PROXY_OVERRIDE)) {
ProxyController.getInstance().setProxyOverride(proxyConfig, executor, listener);
Log.e("Done","Proxy is set");
} else {
Log.e("Cant","No proxy");
}
}

在些做下记录