I would like to check internet connectivity type in Windows Universal Application.
- Not Connected
- Connected via WLAN(WiFi)
- Connected via WWAN(Cellular Data)
- Connected to a metered network
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();
1. Check Internet Connection Availability
To check whether internet connected or not use
GetIsNetworkAvailable
method ofNetworkInterface
class.2. Check Internet Connection Availability via WWLN (WiFi)
To check whether internet connected via WWAN use
IsWlanConnectionProfile
property ofConnectionProfile
class3. Check Internet Connection Availability via WWAN (Mobile)
To check whether internet connected via WWAN use
IsWwanConnectionProfile
property ofConnectionProfile
classReference
Hippiehunter Answer
4. Check Metered network
To check whether Internet reachable via a metered connection or not, use
GetConnectionCost
method onNetworkInterface
class.Reference (More detailed answer here)
1. https://msdn.microsoft.com/en-us/library/windows/apps/xaml/JJ835821(v=win.10).aspx
2. https://msdn.microsoft.com/en-us/library/windows/apps/xaml/windows.networking.connectivity.networkcosttype.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-1
5. Manage network availability changes
To sense the significant network availability changes, use event
NetworkStatusChanged
ofNetworkInformation
classReferences
https://developerinsider.co/check-internet-connectivity-in-uwp/ https://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj835820.aspx https://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh452991.aspx
Hope it helpful to someone.
I use
NetworkInformation.GetInternetConnectionProfile().IsWlanConnectionProfile
andIsWwanConnectionProfile
. If neither istrue
, it should mean you're on Ethernet or something like that.Keep in mind that
GetInternetConnectionProfile()
can return null and can falsely return that there is an active internet connection when the connection is active but DHCP has failed.