0

I am developing app in Xamarin Forms using Visual Studio 2022 for Mac.

For Android 12 API level 31, I am getting SSID as <unknown ssid>

I have added below location permissions in manifest file:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

I have written below code to get SSID.

public string GetWifiDetails()
    {
        var wifiManager = (WifiManager)Application.Context
                                .GetSystemService(Context.WifiService);
        return wifiManager.ConnectionInfo.SSID;
    }

At runtime it is asking user for both Precise and Approximate location.

I have to select Precise because even if I select Approximate it is asking to select Precise location. So I select Precise location and While using the app option.

With above code, on Android OS which are before Android 12, it is working fine but for Android 12 API level 31 it is showing <unknown ssid>

Somewhere I read that wifiManager.ConnectionInfo is deprecated so I have tried using below code:

public string GetWifiDetails()
    {
   ConnectivityManager cm = Android.App.Application.Context.GetSystemService(Context.ConnectivityService) as ConnectivityManager;
        Network n = cm.ActiveNetwork;
       // NetworkCapabilities netCaps = cm.GetNetworkCapabilities(n);
        WifiInfo wifiInfo = (WifiInfo)cm.GetNetworkCapabilities(n).TransportInfo;
        return wifiInfo.SSID;
}

In this WifiInfo is null but in TransportInfo as well it is showing <unknown ssid>

I think even if wifiManager.ConnectionInfo is deprecated we can use it.

I am not getting what is exactly missing while going through above codes or is any other code or permissions need to add to get SSID for Android 12 API level 31?

BSB
  • 277
  • 1
  • 10

0 Answers0