gpt4 book ai didi

android - 代理设置在 Android 系统 Webview 的最后一次更新后停止工作

转载 作者:行者123 更新时间:2023-11-29 01:01:41 32 4
gpt4 key购买 nike

在 Android 系统 Webview 的最后一次更新(2018 年 5 月 30 日)之后,代理设置对我停止工作,代理不再适用于 webview。在其他带代理的浏览器中也是一样的效果,代理不设置,被屏蔽的网站打不开,ip不变。返回的错误是主机不是解析器或连接失败。我的设备是 Nexus 5X,Android 8.1.0。还有其他人遇到同样的问题吗?

我用它来设置代理:

private static boolean setProxyKKPlus(WebView webView, String host, int port, String applicationClassName) {
Log.d(LOG_TAG, "Setting proxy with >= 4.4 API.");

Context appContext = webView.getContext().getApplicationContext();
System.setProperty("http.proxyHost", host);
System.setProperty("http.proxyPort", port + "");
System.setProperty("https.proxyHost", host);
System.setProperty("https.proxyPort", port + "");
try {
Class applictionCls = Class.forName(applicationClassName);
Field loadedApkField = applictionCls.getField("mLoadedApk");
loadedApkField.setAccessible(true);
Object loadedApk = loadedApkField.get(appContext);
Class loadedApkCls = Class.forName("android.app.LoadedApk");
Field receiversField = loadedApkCls.getDeclaredField("mReceivers");
receiversField.setAccessible(true);
ArrayMap receivers = (ArrayMap) receiversField.get(loadedApk);
for (Object receiverMap : receivers.values()) {
for (Object rec : ((ArrayMap) receiverMap).keySet()) {
Class clazz = rec.getClass();
if (clazz.getName().contains("ProxyChangeListener")) {
Method onReceiveMethod = clazz.getDeclaredMethod("onReceive", Context.class, Intent.class);
Intent intent = new Intent("android.intent.action.PROXY_CHANGE");

onReceiveMethod.invoke(rec, appContext, intent);
}
}
}

Log.d(LOG_TAG, "Setting proxy with >= 4.4 API successful!");
return true;
} catch (Exception e) {
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
String exceptionAsString = sw.toString();
Log.v(LOG_TAG, e.getMessage());
Log.v(LOG_TAG, exceptionAsString);
}
return false;
}

最佳答案

此代码适用于我的环境(Chrome 67 + Android 7.0)

for (Object receiverMap : receivers.values()) {
for (Object rec : ((ArrayMap) receiverMap).keySet()) {
Class clazz = rec.getClass();

boolean targetReceiverFound = false;
if (clazz.getName().contains("ProxyChangeListener")) {
targetReceiverFound = true;
} else {
final Field[] obfuscatedFields = clazz.getDeclaredFields();
for (Field f : obfuscatedFields) {
if (f.getType().getName().contains("ProxyChangeListener")) {
targetReceiverFound = true;
break;
}
}
}

if (targetReceiverFound) {
// invoke onReceive() here
}
}
}

关于android - 代理设置在 Android 系统 Webview 的最后一次更新后停止工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50667178/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com