For getting the list of available wifi networks, you can use the ScanResults Property of Android.Net.Wifi.WifiManager Class. For example:
var wifiManager = (WifiManager)GetSystemService(Context.WifiService);
//open wifi
if (!wifiManager.IsWifiEnabled)
wifiManager.SetWifiEnabled(true);
var wifiList = wifiManager.ScanResults;
To do this, you will need to enable all wifi related capabilities in your app's manifest like:
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
To set the static IPs, there is no open API can do this work. And the Apis like Android.Provider.Settings.System.WifiStaticGateway
are obsolete, usually we use reflection in tradition Java android application to set the WifiConfiguration
like in this case: How to configue a static IP address, netmask, gateway programmatically on Android 3.x or 4.x.
Although here in xamarin, the default WifiConfiguration
is like this:
{* ID: -1 SSID: null BSSID: null PRIO: 0
KeyMgmt: Protocols:
AuthAlgorithms:
PairwiseCiphers:
GroupCiphers:
PSK:
IP assignment: UNASSIGNED
Proxy settings: UNASSIGNED
{LinkAddresses: [] Routes: [] DnsAddresses: [] Domains: nullMTU: 0}
}
but after some researching, I found that fields like ipAssignment
in default Android WifiConfiguration.java are not available in xamarin.android app. We don't know how Xamarin.Android encapsulate its WifiConfiguration
.
I couldn't find a way to change its IP assignment
and Proxy settings
, so I personally doubt setting static IP address can be done unless we know how WifiConfiguration
of Xamarin.Android looks like.