标签:
public static void setObjField(Object obj, Object value, String name) throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException { Field f = obj.getClass().getDeclaredField(name); f.setAccessible(true); f.set(obj, value); } public static void setProxy(WifiConfiguration wifiConf) throws SecurityException, IllegalArgumentException, NoSuchFieldException, IllegalAccessException, NoSuchMethodException, ClassNotFoundException, InstantiationException, InvocationTargetException { setEnumField(wifiConf, "STATIC", "proxySettings"); Object linkProperties = getField(wifiConf, "linkProperties"); Class proxyPropertiesClass = Class .forName("android.net.ProxyProperties"); Constructor c = proxyPropertiesClass.getConstructor(String.class, Integer.TYPE, String.class); c.setAccessible(true); Object properties = c.newInstance("192.168.5.121", 9999, null); setObjField(linkProperties,properties,"mHttpProxy"); setObjField(wifiConf,linkProperties,"linkProperties"); }
标签:
原文地址:http://www.cnblogs.com/huangjianan/p/4244562.html