0

I have a function similar to this:

private bool IsConnected()
{
    if (DeviceInfo.DeviceType == DeviceType.Unknown)
        return false;

    var current = Connectivity.NetworkAccess;

    if (current == NetworkAccess.Internet)
        return true;

    return false;
}

My teammates have reported zero issues with this function, and are using a variety of devices. My personal device is a Google Pixel 3, using Google Fi and Google VPN. When I cut it into airplane mode, I see Connectivity.NetworkAccess is set to NetworkAccess.None. However, when I leave airplane mode off and turn both Mobile Data and Wifi off explicitly, I see Connectivity.NetworkAccess is set to NetworkAccess.Internet.

Related to this, the Connectivity.ConnectionProfiles reports a single profile: ConnectionProfile.Unknown.

Is this expected behavior? Should I check a combination of Connectivity.ConnectionProfiles as well as Connectivity.NetworkAccess in attempting to determine if the device actually is connected to a network?

  • It might be worth debugging at a lower level than the abstraction. Take a look at the [Android APIs being used](https://github.com/xamarin/Essentials/blob/master/Xamarin.Essentials/Connectivity/Connectivity.android.cs) to further understand and maybe run some of these locally to ensure that it's not hitting an invalid code path. – Jon Douglas May 30 '19 at 15:24

1 Answers1

0

If you can't access the internet and Connectivity.NetworkAccess is NetworkAccess.Internet then it is not expected behavior.

You can submit the issue on their github: https://github.com/xamarin/Essentials/issues

Ivan Ičin
  • 9,672
  • 5
  • 36
  • 57