Search code examples
xamarin.androidstatusinternet-connection

Xamarin Android internet connectivity status checking independently of HTTP request or Ping methods


I can detect internet connectivity status by the HTTP web request, ping or socket methods but I am searching a way that it is done independently of remote server connection. For example, I request a web page like "www.google.com" (or 8.8.8.8) and when the status code of HTTP request is OK then I realize that internet connectivity is OK. But I don't prefer this way in general because if the remote server was down, consequently mentioned methods report the internet is unavailable.

Is there an independent way to do that?


Solution

  • There is a Xamarin plugin which does all this stuff for connectivity check. You can add Xam.Plugin.Connectivity nuget package in your Android and Core projects for this.

    How to use it:

    if(CrossConnectivity.Current.IsConnected)
    {
        //Connection is available      
    }
    else
    {
        //Connection is not available
    }
    

    Here is a documentation on it. https://jamesmontemagno.github.io/ConnectivityPlugin/