You need to go through the followings:
The
Connectivity
class lets you monitor for changes in the device's network conditions, check the current network access, and how it is currently connected:
Xamarin.Essentials: Connectivity - Xamarin | Microsoft Learn[
^]
High level steps from it:
1. Provide
AccessNetworkState
permission
2. Add a reference to
Xamarin.Essentials
in your class
3. With above, you can check network access as:
var current = Connectivity.NetworkAccess;
if (current == NetworkAccess.Internet)
{
}
You can also setup for any connectivety change trigger as:
public class ConnectivityTest
{
public ConnectivityTest()
{
Connectivity.ConnectivityChanged += Connectivity_ConnectivityChanged;
}
void Connectivity_ConnectivityChanged(object sender, ConnectivityChangedEventArgs e)
{
var access = e.NetworkAccess;
var profiles = e.ConnectionProfiles;
}
}
More details on how to use Xamarin.Essentials:
Easily Check Mobile Device Connectivity with Xamarin.Essentials - Xamarin Blog[
^]