I am trying to set ssid,proxy,ipsetting in android through reflection and i m successfully for ssid and brief ip settings in android via reflection , my issue is i want to set proxy settings programtically via reflection and most of the code i goggled say implementation of STATIC and NONE options but devices i hv proxy options as NONE and MANUAL is both same ? below is code for my proxy plz suggest what exactly should i change to work for manual proxy implementation :
public static void setWifiProxySettings(WifiConfiguration config,
WifiSetting wifiSetting) {
try {
Object linkProperties = getField(config, "linkProperties");
if (null == linkProperties)
return;
Class proxyPropertiesClass = Class
.forName("android.net.ProxyProperties");
Class[] setHttpProxyParams = new Class[1];
setHttpProxyParams[0] = proxyPropertiesClass;
Class lpClass = Class.forName("android.net.LinkProperties");
Method setHttpProxy = lpClass.getDeclaredMethod("setHttpProxy",
setHttpProxyParams);
setHttpProxy.setAccessible(true);
Class[] proxyPropertiesCtorParamTypes = new Class[3];
proxyPropertiesCtorParamTypes[0] = String.class;
proxyPropertiesCtorParamTypes[1] = int.class;
proxyPropertiesCtorParamTypes[2] = String.class;
Constructor proxyPropertiesCtor = proxyPropertiesClass
.getConstructor(proxyPropertiesCtorParamTypes);
Object[] proxyPropertiesCtorParams = new Object[3];
URL proxyUrl = new URL(wifiSetting.getProxyHostName());
proxyPropertiesCtorParams[0] = proxyUrl.getHost();
proxyPropertiesCtorParams[1] = proxyUrl.getPort();
proxyPropertiesCtorParams[2] = null;
Object proxySettings = proxyPropertiesCtor
.newInstance(proxyPropertiesCtorParams);
Object[] params = new Object[1];
params[0] = proxySettings;
setHttpProxy.invoke(linkProperties, params);
setProxySettings("STATIC", config);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void setProxySettings(String assign, WifiConfiguration wifiConf)
throws SecurityException, IllegalArgumentException,
NoSuchFieldException, IllegalAccessException {
setEnumField(wifiConf, assign, "proxySettings");
}
I have written below apis for proxy in android via reflection :
EDIT : API FOR LOLLIPOP [the above api for proxy and ip wont work in latest Andriod L ]