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 uses reflection to set up WiFi proxy