A huge amount of the currently released apps in the Store does a check upon app start up to see if connectivity is available. If this is not the case, then the user is redirected to an offline page, and there is no way to continue use of the app.
This is a major concern, when several of the apps does not correctly check for connectivity. One such case, is when the user connects to a VPN. In that case the main connection will be changed to ‘Limited’ even though the user still has an active connection to the internet.
The below snippet will check all the connection profiles for internet access:
|
1 2 3 4 5 6 7 8 9 10 11 |
public static bool IsConnected
{
get
{
var profiles = NetworkInformation.GetConnectionProfiles();
var internetProfile = NetworkInformation.GetInternetConnectionProfile();
return profiles.Any(s => s.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess)
|| (internetProfile != null
&& internetProfile.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess);
}
} |
The naive way to check for internet access would be:
NetworkInformation.GetInternetConnectionProfile().GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess , but this approach fails in the scenario described above.
Just a little warning, the method described here is NOT bulletproof.
internetProfile can be NULL, in that case this code throws an exception. A null check on internetProfile should be added.
Ahh, you are absolutely correct. I initially had this check, but somehow it got left out when I updated the post.
Thanks for sharing! I had issues with the Internet connection and I only suspected it’s because of Ethernet connection. I will try your solution and I am almost sure it will help me! )
–
Roman Empire