Skip to content
This repository was archived by the owner on May 15, 2024. It is now read-only.
This repository was archived by the owner on May 15, 2024. It is now read-only.

Connectivity working but not as expected. #698

@rpascalegh

Description

@rpascalegh

Connectivity working but not as expected.
I installed Xamarin Essentials 1.01. When testing the Connectivity I am finding the following.
When I switch to Airplane mode it will display local. If check the status again it will show none.
If i put a 1 sec sleep at the top of the connectivity changed it works correctly. It looks like when I go into airplane mode the phone makes two changes. It will go from internet to local and then local to none once airplane mode is turned on. The first change to locaI is triggering a connectivity change so I see local, but the second change to none doesn't trigger the event again so even though its none I am not getting that response unless I recheck the values. Am I doing something wrong or is the delay the only solutions?

Turn on airplane mode to disable wifi and cell
Expected Behavior
To display NONE.

Actual Behavior
displays LOCAL (but state has actually changed to NONE after LOCAL. Will show NONE if manually recheck values.)

Basic Information
Version with issue: Xamarin Essentials Version 1.0.1 /Xamarin Forms 4.0.0.954569-pre3
Last known good version: never tested, new.
IDE:
Platform Target Frameworks: Tried 8.0(oreo) and 9.0(P)
iOS:
Android: 8.1OREO
Affected Devices: Android
Testing on Galaxy S9+ running Android 8.0.0

Testing code behind

private void Connectivity_ConnectivityChanged(object sender, ConnectivityChangedEventArgs e)
{
System.Threading.Thread.Sleep(1000); // THIS FIXES ISSUE
var access = e.NetworkAccess;
var profiles = e.ConnectionProfiles;
LabelStatus.Text = access + "--" + profiles;
UpdateLabels();
}

private void UpdateLabels()
    {
        var current = Connectivity.NetworkAccess;
        if (current == NetworkAccess.Internet)
        {
            LabelConnect.Text = "Internet";
        }
        else if (current == NetworkAccess.None)
        {
            LabelConnect.Text = "NONE";
        }
        else if (current == NetworkAccess.Local)
        {
            LabelConnect.Text = "local";
        }
        else LabelConnect.Text = "empty";

        var profiles = Connectivity.ConnectionProfiles;
        if (profiles.Contains(ConnectionProfile.WiFi))
        {
            LabelConnect2.Text = "wifi";// Active Wi-Fi connection.
        }
        else LabelConnect2.Text = "nowifi";
        }

    protected override void OnAppearing()
    {
        Connectivity.ConnectivityChanged += Connectivity_ConnectivityChanged;
    }

    protected override void OnDisappearing()
    {
        Connectivity.ConnectivityChanged -= Connectivity_ConnectivityChanged;
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions