Here are the steps to retrieving the current Wi-Fi signal strength using the deprecated capabilities:
Step 1:
On the Android device, tap
Settings > Location
then tap
App permission
Scroll down until you find your App.
Tap your app and select any option other than "Deny".
Step 2:
Ensure you have the following in your project AndroidManifest.xml:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
Step 3:
Include the following code in the class where you wish to capture the Wi-Fi signal strength using the deprecated capabilities:
using System;
using System.Linq;
namespace YourNamespaceHere
{
public static class Device
{
private static Android.Net.Wifi.WifiManager deviwifimanager;
private static Android.Content.Context devicontext;
public static void PassContext(Android.Content.Context context00)
{
devicontext = context00;
deviwifimanager = (Android.Net.Wifi.WifiManager)devicontext.GetSystemService(Android.Content.Context.WifiService);
devwifimanager.StartScan();
}
public static Int32 SignalStrength()
{
Int32 temp00 = 0;
string text00 = null;
try
{
var wifilist = deviwifimanager.ScanResults;
foreach (var wifilistitem in wifilist)
{
temp00 = Android.Net.Wifi.WifiManager.CalculateSignalLevel(wifilistitem.Level, 100);
text00 = wifilistitem.Ssid;
// add your code to process signal level and SSID as required
}
}
catch
{
temp00 = 0;
}
return temp00;
}
}
}
Step 4:
Add the following code in the OnCreate method in MainActivity.cs:
Device.PassContext(this);