首页 > 代码库 > Android利用反射实现设置wifi代理

Android利用反射实现设置wifi代理

	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");	}

  

Android利用反射实现设置wifi代理