I have the following method:
public static bool IsNetworkConnected()
{
ConnectionProfile InternetConnectionProfile = NetworkInformation.GetInternetConnectionProfile();
IReadOnlyList<ConnectionProfile> connectionProfile = NetworkInformation.GetConnectionProfiles();
if (InternetConnectionProfile == null)
return false;
else
return true;
}
It works fine when I'm connected to the internet in a typical way - via LAN cable or Wi-Fi. When I'm using my 3G USB modem it returns false (InternectConnectionProfile
is null). Why is that? How can I fix it?
You may consider pinging a server on the internet. This is not the 100% answer to your question but may be helpful from a different point of view.
using System.Net;
using System.Net.NetworkInformation;
using (Ping Packet = new Ping())
{
if (Packet.Send(IPAddress.Parse(IP), 1000, new byte[] { 0 }).Status == IPStatus.Success))
{
// ...
}
}
Try
public static bool IsConnectedToInternet()
{
ConnectionProfile connectionProfile = NetworkInformation.GetInternetConnectionProfile();
return (connectionProfile!=null && connectionProfile.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess);
}
This might help you
http://social.msdn.microsoft.com/Forums/en-US/winappswithhtml5/thread/a7ba014c-3a31-4ff3-ba10-0c835305828b/