Record the proxy code set in Android and maybe some friends can use it.
Apply to 4.4.3 on 5.0 android.net.ProxyProperties can't find an estimate API was taken off by Google 4.4.4 haven't yet tried to estimate the API is still
Privatestatic String Notproxy ="";No, the proxy list.PrivateStatic list<string> List;Type 1 set WiFi setting to 0 is clear agentPublicStaticvoidSetwifi (Context context,Final String IP,Finalint port,Finalint type)Throws SecurityException, IllegalArgumentException, Nosuchfieldexception, Illegalaccessexception, Nosuchmethodexception, ClassNotFoundException, Instantiationexception, invocationtargetexception {Final Wifimanager Wifimanager = (wifimanager) context.getsystemservice (Context.wifi_service);Final String SSID = Wifimanager.getconnectioninfo (). Getssid (); list<wificonfiguration> Configurednetworks = Wifimanager.getconfigurednetworks (); Changenotproxy ();for (Wificonfiguration config:configurednetworks) {LOG.D ("Txy","Current SSID is" + CONFIG. SSID);if (config. Ssid.tostring (). Contains (Common.myssid)) {Which wireless setup proxy class Proxypropertiesclass = class. forname ("Android.net.ProxyProperties"); Constructor C = proxypropertiesclass.getconstructor (String.class, Integer.type, String.class); C.setaccessible (true);WIFIIP for proxy IP address such as: 192.168.0.111 wifiport for proxy port such as 888 setproxy (config, type = =0?Null:c.newinstance (IP, port, notproxy)), type); Wifimanager.updatenetwork (config);Break }else {Wifimanager.removenetwork (Config.networkid); }} wifimanager.disconnect (); Wifimanager.reconnect (); }PublicStaticvoidSetobjfield (Object obj, object value, String name)Throws SecurityException, Nosuchfieldexception, IllegalArgumentException, illegalaccessexception {Field f = Obj.getclass (). Getdeclaredfield (name); F.setaccessible (true); F.set (obj, value); }Type 1 set WiFi setting to 0 is clear agentPublicStatic wificonfigurationSetProxy (wificonfiguration wificonf, Object properties,int type)Throws SecurityException, IllegalArgumentException, Nosuchfieldexception, Illegalaccessexception, Nosuchmethodexception, ClassNotFoundException, Instantiationexception, invocationtargetexception {if (type = =0) Setenumfield (wificonf,"NONE","Proxysettings");else Setenumfield (wificonf,"STATIC","Proxysettings"); Object linkproperties = GetField (wificonf,"Linkproperties"); Setobjfield (Linkproperties, properties,"Mhttpproxy"); Setobjfield (wificonf, Linkproperties, "linkproperties"); return wificonf;} public static void setenumfield (Object obj, string value, String name) throws SecurityException, Nosuchfieldexception, IllegalArgumentException, illegalaccessexception {Field f = obj.getclass (). GetField (name); F.set (obj, enum.valueof ((class<enum>) F.gettype (), value)); } public static Object getField ( Object obj, String name) throws SecurityException, Nosuchfieldexception, IllegalArgumentException, illegalaccessexception {Field f = obj.getclass (). GetField (name); Object out = F.get (obj); return out;}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21st
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
5.0
PrivateStatic list<string> List;No, the proxy list.@RequiresApi (API = Build.version_codes. LOLLIPOP)PublicStaticvoidSet_proxy (Application context, string IP, string port,int type)Throws Throwable {Wifimanager Wifimanager = (wifimanager) context.getsystemservice (Context.wifi_service); Wifiinfo WI = Wifimanager.getconnectioninfo (); list<wificonfiguration> Configurednetworks = Wifimanager.getconfigurednetworks (); Changenotproxy ();for (Wificonfiguration Config:configurednetworks) {Which wireless setup agent you need to giveif (config. Ssid.equals (Wi.getssid ())) {Class proxysettings = Class.forName ("Android.net.ipconfiguration$proxysettings"); class[] Setproxyparams =New class[2]; setproxyparams[0] = proxysettings; setproxyparams[1] = Proxyinfo.class; Method SetProxy = Config.getclass (). Getdeclaredmethod ("SetProxy", setproxyparams); Setproxy.setaccessible (true);if (type = =0) {object[] Methodparams =new object[2]; Methodparams[0] = Enum.valueof (proxysettings, "NONE"); Methodparams[1] = null; Setproxy.invoke (config, methodparams); } else {proxyinfo desiredproxy = Proxyinfo.builddirectproxy (IP, Integer.parseInt (port), list); object[] Methodparams = new object[2]; MethodParams[0] = enum.valueof (proxysettings, "STATIC"); Methodparams[1] = Desiredproxy; Setproxy.invoke (config, methodparams); } //save the settings wifimanager.updatenetwork (config); Wifimanager.disconnect (); Wifimanager.reconnect (); break;} } }
Android WIFI settings Agent Code 4.4.3--5.0