码迷,mamicode.com
首页 > 移动开发 > 详细

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

时间:2015-01-23 17:45:21      阅读:315      评论:0      收藏:0      [点我收藏+]

标签:

	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代理

标签:

原文地址:http://www.cnblogs.com/huangjianan/p/4244562.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!