Forum Xamarin.Android

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Verify Connection internet

I'm wanting to check connection NET, but when I lose the connection using this code my test does not work well, even removing the network cable the connection status is true. (Test in Emulator Android)

Code:

        ConnectivityManager conMannager = (ConnectivityManager)GetSystemService(Context.ConnectivityService);

        if (conMannager.GetNetworkInfo(ConnectivityType.Mobile).GetState() == NetworkInfo.State.Connected ||

            conMannager.GetNetworkInfo(ConnectivityType.Mobile).GetState() == NetworkInfo.State.Connecting)
        {
            RunOnUiThread(() =>
               {
                   statusWifi.Text = "CONECTADO";
               });
        }

        if (conMannager.GetNetworkInfo(0).GetState() == NetworkInfo.State.Disconnected ||

            conMannager.GetNetworkInfo(0).GetState() == NetworkInfo.State.Disconnecting)
        {
            RunOnUiThread(() =>
            {
                statusWifi.Text = "DESCONECTADO";
            });
        }
Sign In or Register to comment.