Background
Checking the state of the network can have very different results: wired connected with or without internet, GSM, an so on. If you only want to know if the user is connected to the internet there isn't any short way, so I made this litle check to have as a snippet of code to our apps.
Using the code
Just copy-paste and use this code:
var cx = new Windows.Networking.Connectivity.NetworkInformation.getInternetConnectionProfile();
if ((!('getNetworkConnectivityLevel' in cx)) || ((cx.getNetworkConnectivityLevel()) < 3)) {
alert('Debes estar conectado a internet para ver el contenido. Revisa tu conexión y vuelve a intentar.', 'Atención');
return false;
}
Points of interest
For more information about network state check: http://msdn.microsoft.com/en-US/library/windows/apps/windows.networking.connectivity.networkinformation
History
- 19/03/2013: First version.