WebView Android代理我知道如何手动设置代理,并在我的WebView中使用它。设置->无线网络->移动网络->接入点名称->telkila。现在输入代理服务器地址和端口(80)。WebView.enablePlatformNotiations();但是我可以从代码中设置代理设置吗?所以我的用户不需要手动设置?谢谢
3 回答
慕雪6442864
TA贡献1812条经验 获得超5个赞
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){ }
- 3 回答
- 0 关注
- 504 浏览
添加回答
举报
0/150
提交
取消