Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin getting wifi signal strength

Tags:

c#

.net

xamarin

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);
like image 963
Krzysztofz01 Avatar asked Nov 01 '25 14:11

Krzysztofz01


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.-

like image 164
pinedax Avatar answered Nov 04 '25 02:11

pinedax