如何检查连接的3G网络连接状态?(How to check internet connection

2019-06-26 16:06发布

我有以下方法:

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

通过局域网电缆或无线网络连接 - 当我连接到互联网,在一个典型的方式,它工作正常。 当我用我的3G USB调制解调器返回false( InternectConnectionProfile为空)。 这是为什么? 我怎样才能解决这个问题?

Answer 1:

您可以考虑在互联网上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))
    {
       // ...
    }
}


Answer 2:

尝试

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


Answer 3:

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



文章来源: How to check internet connection status over 3G connection?