2012-10-15 86 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

相關問題