如何通过3G连接检查互联网连接状态?

我有以下方法:

public static bool IsNetworkConnected() { ConnectionProfile InternetConnectionProfile = NetworkInformation.GetInternetConnectionProfile(); IReadOnlyList connectionProfile = NetworkInformation.GetConnectionProfiles(); if (InternetConnectionProfile == null) return false; else return true; } 

当我以典型的方式连接到互联网时 – 通过LAN电缆或Wi-Fi,它工作正常。 当我使用我的3G USB调制解调器时,它返回false( InternectConnectionProfile为null)。 这是为什么? 我该如何解决?

您可以考虑在互联网上ping服务器。 这不是您问题的100%答案,但从不同的角度来看可能会有所帮助。

 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)) { // ... } } 

尝试

 public static bool IsConnectedToInternet() { ConnectionProfile connectionProfile = NetworkInformation.GetInternetConnectionProfile(); return (connectionProfile!=null && connectionProfile.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess); } 

这可能对你有帮助http://social.msdn.microsoft.com/Forums/en-US/winappswithhtml5/thread/a7ba014c-3a31-4ff3-ba10-0c835305828b/