Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Get Wifi info with android 9

$
0
0

Hi,

I'm building an app where I need to know the wifi info like the ssid. Until android 8 it worked fine, but since I update to android 9 it gives back "unknown_ssid".
I used a Dependency:

This is the interface in the PCL:

    public interface IWlanInfo
    {
        string GetCurrentSSID();

        string GetCurrentBSSID();

        bool GetCurrentIsHidden();
    }

This is the implementation at the droid project:

[assembly: Dependency(typeof(DroidProject.Droid.WlanInfoAndroid))]
namespace DroidProject.Droid
{    
    public class WlanInfoAndroid : IWlanInfo
    {        
        public string GetCurrentBSSID()
        {                                    
            return ((WifiManager)Android.App.Application.Context.GetSystemService(Context.WifiService)).ConnectionInfo.BSSID;
        }

        public bool GetCurrentIsHidden()
        {
            return ((WifiManager)Android.App.Application.Context.GetSystemService(Context.WifiService)).ConnectionInfo.HiddenSSID;
        }

        public string GetCurrentSSID()
        {
            return ((WifiManager)Android.App.Application.Context.GetSystemService(Context.WifiService)).ConnectionInfo.SSID;
        }
    }
}

And this is how I call it at the PCL:

        var ssid = DependencyService.Get<IWlanInfo>().GetCurrentSSID().Trim('"');
            var bssid = DependencyService.Get<IWlanInfo>().GetCurrentBSSID();
            var isHidden = DependencyService.Get<IWlanInfo>().GetCurrentIsHidden();

Does anybody know how I can make it work again?
Thanks in advance!


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>