Xamarin getting wifi signal strength

Viewed 1963

Is it possible in Xamarina to get information about the signal strength of all available wifi nearby? I am working on an application that collects and processes information about nearby wifi networks. I also want to get this information without having to connect to a given network.

FIX (The application was not allowed to perform the scan):

//Define permissions
private string[] permissions = new string[]
{
   Android.Manifest.Permission.AccessFineLocation
};

//Permission check
ActivityCompat.RequestPermissions(this, permissions, 0);
1 Answers

In Xamarin.Android you can use the code below to get the Wifi Connections along with their strength from 0 to 100.

using Android.Net.Wifi;

...

var wifiMgr = (WifiManager)GetSystemService(WifiService);

var wifiList = wifiMgr.ScanResults;
foreach (var item in wifiList)
{
    var wifiLevel = WifiManager.CalculateSignalLevel(item.Level, 100);
    Console.WriteLine($"Wifi SSID: {item.Ssid} - Strengh: {wifiLevel}");
}

You will need to add these two permissions to the Manifest:

ACCESS_FINE_LOCATION and ACCESS_WIFI_STATE

And make sure you request authorization for the ACCESS_FINE_LOCATION.

Hope this helps.-

Related