I have an Android application created in C# using Xamarin.
This is essentially a web browser with some additional functionalities and now I would like add the option to set up a proxy to use. In the application I use WebView for connection to websites.
I tried to implement solution from this topic (How can I set ProxySettings and ProxyProperties on Android Wi-Fi connection using Java?), but there is no linkProperties in WifiConfiguration. This is how it looks like:
private static Java.Lang.Object getField(Java.Lang.Object obj, String name)
{
Field f = obj.Class.GetField(name);
Java.Lang.Object o = f.Get(obj);
return o;
}
public void SetHttpProxy(string proxyServerAddress, int proxyServerInt)
{
try
{
var wifiManager = context.GetSystemService(Context.WifiService) as WifiManager;
if (!wifiManager.IsWifiEnabled)
return;
var configurationList = wifiManager.ConfiguredNetworks;
var cur = wifiManager.ConnectionInfo.NetworkId;
var configuration = configurationList.FirstOrDefault(conf => conf.NetworkId == cur);
getField(configuration, "linkProperties");
}
catch (Exception e)
{
throw;
}
}