首页 > 代码库 > 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代理
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。