2012-10-15 43 views
1

我使用C完成了Metro应用程序#& XAML。我正在使用WebView控件加载URL,并使用通知来更新图块。如果机器未连接到互联网,则平铺图和网页视图都是空白的。我想显示某种消息,指出应用程序无法连接到Internet。如果没有互联网连接,则显示错误消息

如何检查Internet连接?在try catch块或什么?

回答

2

你看过网络信息示例吗?它显示了如何从应用程序内检查互联网连接。短版...

var connectionProfile = Windows.Networking.Connectivity.NetworkInformation.GetInternetConnectionProfile(); 

switch (connectionProfile.GetNetworkConnectivityLevel()) 
       { 
        case NetworkConnectivityLevel.None: 
         connectionProfileInfo += "Connectivity Level : None\n"; 
         break; 
        case NetworkConnectivityLevel.LocalAccess: 
         connectionProfileInfo += "Connectivity Level : Local Access\n"; 
         break; 
        case NetworkConnectivityLevel.ConstrainedInternetAccess: 
         connectionProfileInfo += "Connectivity Level : Constrained Internet Access\n"; 
         break; 
        case NetworkConnectivityLevel.InternetAccess: 
         connectionProfileInfo += "Connectivity Level : Internet Access\n"; 
         break; 
       } 

在尝试使用WebView并相应地提示用户之前进行检查。

+0

太棒了,非常感谢。我也会查找网络示例。 – tempid

相关问题