private static bool IsInternetConnected() { Windows.Networking.Connectivity.ConnectionProfile connections = Windows.Networking.Connectivity.NetworkInformation.GetInternetConnectionProfile(); bool internet = (connections != null) && (connections.GetNetworkConnectivityLevel() == Windows.Networking.Connectivity.NetworkConnectivityLevel.InternetAccess); return(internet); }
private bool CheckInternetAccess() { bool internetAccess = false; Windows.Networking.Connectivity.ConnectionProfile connectionProfile = Windows.Networking.Connectivity.NetworkInformation.GetInternetConnectionProfile(); if (connectionProfile != null) { var connectivityLevel = connectionProfile.GetNetworkConnectivityLevel(); if (connectivityLevel == Windows.Networking.Connectivity.NetworkConnectivityLevel.ConstrainedInternetAccess || connectivityLevel == Windows.Networking.Connectivity.NetworkConnectivityLevel.InternetAccess) { internetAccess = true; } } return(internetAccess); }
private bool IsConnectedToInternet() { Windows.Networking.Connectivity.ConnectionProfile connectionProfile = Windows.Networking.Connectivity.NetworkInformation.GetInternetConnectionProfile(); return(connectionProfile != null && connectionProfile.GetNetworkConnectivityLevel() == Windows.Networking.Connectivity.NetworkConnectivityLevel.InternetAccess); }
internal ConnectionProfile(Windows.Networking.Connectivity.ConnectionProfile profile) { _profile = profile; }
async void WLAN() { /* * if (!System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable()) * { * await new Windows.UI.Popups.MessageDialog("当前设备没有联接网络!", "提示").ShowAsync(); * return; * } */ Windows.Networking.Connectivity.ConnectionProfile cp = Windows.Networking.Connectivity.NetworkInformation.GetInternetConnectionProfile(); if (cp == null) { await new Windows.UI.Popups.MessageDialog("当前设备没有联接网络!", "提示").ShowAsync(); PR.IsActive = false; return; } if (cp.IsWwanConnectionProfile) { ContentDialog dialog = new ContentDialog() { Title = "提示", Content = "当前使用的是蜂窝网络数据,可能会产生额外的费用。", PrimaryButtonText = "确定", SecondaryButtonText = "取消", FullSizeDesired = false }; dialog.PrimaryButtonClick += (sender, args) => { //Visbale = Windows.UI.Xaml.Visibility.Collapsed; //(Windows.UI.Xaml.Window.Current.Content as Windows.UI.Xaml.Controls.Frame).Navigate(typeof(WinMain.MainPage)); var frame = Window.Current.Content as Frame; if (frame != null) { PR.IsActive = false; frame.Navigate(typeof(MainPage)); } //this.Frame.Navigate(typeof(WinMain.MainPage)); }; dialog.SecondaryButtonClick += (sender, args) => { App.Current.Exit(); return; }; await dialog.ShowAsync(); } else if (cp.IsWlanConnectionProfile) { //Visbale = Windows.UI.Xaml.Visibility.Collapsed; //(Windows.UI.Xaml.Window.Current.Content as Windows.UI.Xaml.Controls.Frame).Navigate(typeof(WinMain.MainPage)); //this.Frame.Navigate(typeof(WinMain.MainPage)); var frame = Window.Current.Content as Frame; if (frame != null) { PR.IsActive = false; frame.Navigate(typeof(MainPage)); } } else { await new Windows.UI.Popups.MessageDialog("未知的网络", "网络错误").ShowAsync(); App.Current.Exit(); } }
internal ConnectionProfile(Windows.Networking.Connectivity.ConnectionProfile profile) { _profile = profile; }