I am developing an app in Xamarin.Android using Mvvmcross6. To check the network state, I am currently using the following code:
Is this approach correct? Has anything newly came up in Mvvmcross6?
public void NetworkStatus()
{
_state = NetworkState.Unknown;
//Retrieve the connectivity manager service
var connectivityManager = (ConnectivityManager)Application.Context.GetSystemService(Context.ConnectivityService);
//Check if the network is connected or connecting.
//This means that it will be available,
//or become available in a few seconds.
var activeNetworkInfo = connectivityManager.ActiveNetworkInfo;
if(activeNetworkInfo.IsConnectedOrConnecting)
{
_state = activeNetworkInfo.Type == ConnectivityType.Wifi ? NetworkState.ConnectedWifi : NetworkState.ConnectedData;
}
else
{
_state = NetworkState.Disconnected;
}
}