Source:
public static boolean setWebViewProxy(Context appContext, String host, int port, String exclusionList) { Properties properties = System.getProperties(); properties.setProperty("http.proxyHost", host); properties.setProperty("http.proxyPort", port + ""); properties.setProperty("https.proxyHost", host); properties.setProperty("https.proxyPort", port + ""); properties.setProperty("http.nonProxyHosts", exclusionList); properties.setProperty("https.nonProxyHosts", exclusionList); if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { return false; } try { Class applictionCls = Class.forName("android.app.Application"); Field loadedApkField = applictionCls.getDeclaredField("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(Proxy.PROXY_CHANGE_ACTION); String CLASS_NAME; if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) { CLASS_NAME = "android.net.ProxyProperties"; } else { CLASS_NAME = "android.net.ProxyInfo"; } Class cls = Class.forName(CLASS_NAME); Constructor constructor = cls.getConstructor(String.class, Integer.TYPE, String.class); constructor.setAccessible(true); Object proxyProperties = constructor.newInstance(host, port, exclusionList); intent.putExtra("proxy", (Parcelable) proxyProperties); onReceiveMethod.invoke(rec, appContext, intent); } } } return true; } catch (Exception e) { e.printStackTrace(); } return false; }

Target:
public static boolean setWebViewProxy(Context appContext, String host, int port, String exclusionList) { if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { return false; } Properties properties = System.getProperties(); properties.setProperty("http.proxyHost", host); properties.setProperty("http.proxyPort", Integer.toString(port)); properties.setProperty("https.proxyHost", host); properties.setProperty("https.proxyPort", Integer.toString(port)); properties.setProperty("http.nonProxyHosts", exclusionList); properties.setProperty("https.nonProxyHosts", exclusionList); try { Class applictionCls = Class.forName("android.app.Application"); Field loadedApkField = applictionCls.getDeclaredField("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(Proxy.PROXY_CHANGE_ACTION); String CLASS_NAME; if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) { CLASS_NAME = "android.net.ProxyProperties"; } else { CLASS_NAME = "android.net.ProxyInfo"; } Class cls = Class.forName(CLASS_NAME); Constructor constructor = cls.getConstructor(String.class, Integer.TYPE, String.class); constructor.setAccessible(true); Object proxyProperties = constructor.newInstance(host, port, exclusionList); intent.putExtra("proxy", (Parcelable) proxyProperties); onReceiveMethod.invoke(rec, appContext, intent); } } } return true; } catch (Exception e) { Log.w(TAG, "setWebViewProxy exception", e); } return false; }