I would like to check internet connectivity type in Windows Universal Application.
in order to provide an option for downloading large size content. And also sense the significant network availability changes.
Currently, I'm only able to check whether internet connected or not using GetIsNetworkAvailable
method of NetworkInterface
class.
NetworkInterface.GetIsNetworkAvailable();
Select the Start button, then type settings. Select Settings > Network & internet. The status of your network connection will appear at the top. Windows 10 lets you quickly check your network connection status.
The Network Connectivity Status Indicator (NCSI) is a mechanism that controls the internet connectivity display in the Taskbar, among various other functionalities. NCSI is part of the Network Awareness program which was first introduced in Windows Vista and has been carried out ever since in each version of Windows.
ping (This command will test for the Internet connectivity and DNS functionality.) Example: ping www.netgear.com, ping google.com.
To check whether any network connection is established or not use GetIsNetworkAvailable
method of NetworkInterface
class.
bool isNetworkConnected = NetworkInterface.GetIsNetworkAvailable();
GetIsNetworkAvailable() -
Summary: Indicates whether any network connection is available.
Returns:true
if a network connection is available; otherwise,false
.
To check whether internet connected via WWAN use IsWlanConnectionProfile
property of ConnectionProfile
class
ConnectionProfile InternetConnectionProfile = NetworkInformation.GetInternetConnectionProfile(); bool isWLANConnection = (InternetConnectionProfile == null)?false:InternetConnectionProfile.IsWlanConnectionProfile;
IsWlanConnectionProfile
Summary: Gets a value that indicates if connection profile is a WLAN (WiFi) connection. This determines whether or not WlanConnectionProfileDetails is null.
Returns: Indicates if the connection profile represents a WLAN (WiFi) connection.
To check whether internet connected via WWAN use IsWwanConnectionProfile
property ofConnectionProfile
class
ConnectionProfile InternetConnectionProfile = NetworkInformation.GetInternetConnectionProfile(); bool isWLANConnection = (InternetConnectionProfile == null)?false:InternetConnectionProfile.IsWwanConnectionProfile;
IsWwanConnectionProfile
Summary: Gets a value that indicates if connection profile is a WWAN (mobile) connection. This determines whether or not WwanConnectionProfileDetails is null.
Returns: Indicates if the connection profile represents a WWAN (mobile) connection.
Reference
Hippiehunter Answer
To check whether Internet reachable via a metered connection or not, use GetConnectionCost
method on NetworkInterface
class.
var connectionCost = NetworkInformation.GetInternetConnectionProfile().GetConnectionCost(); if (connectionCost.NetworkCostType == NetworkCostType.Unknown || connectionCost.NetworkCostType == NetworkCostType.Unrestricted) { //Connection cost is unknown/unrestricted } else { //Metered Network }
Reference (More detailed answer here)
1. How to manage metered network cost constraints - MSDN
2. NetworkCostType Enum - MSDN
To sense the significant network availability changes, use eventNetworkStatusChanged
of NetworkInformation
class
// register for network status change notifications networkStatusCallback = new NetworkStatusChangedEventHandler(OnNetworkStatusChange); if (!registeredNetworkStatusNotif) { NetworkInformation.NetworkStatusChanged += networkStatusCallback; registeredNetworkStatusNotif = true; } async void OnNetworkStatusChange(object sender) { // get the ConnectionProfile that is currently used to connect to the Internet ConnectionProfile InternetConnectionProfile = NetworkInformation.GetInternetConnectionProfile(); if (InternetConnectionProfile == null) { await _cd.RunAsync(CoreDispatcherPriority.Normal, () => { rootPage.NotifyUser("Not connected to Internet\n", NotifyType.StatusMessage); }); } else { connectionProfileInfo = GetConnectionProfile(InternetConnectionProfile); await _cd.RunAsync(CoreDispatcherPriority.Normal, () => { rootPage.NotifyUser(connectionProfileInfo, NotifyType.StatusMessage); }); } internetProfileInfo = ""; }
References
Check Internet Connectivity - developerinsider.co
How to manage network connection events and changes in availability - MSDN
How to retrieve network connection information- MSDN
Hope it helpful to someone.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With