InternetConnectionProfile

InternetConnectionProfile

4.检查计量网络要检查是否可以通过计量连接访问 Internet,请使用 NetworkInterface 类上的 GetConnectionCost 方法.var connectionCost = NetworkInformation.GetInternetConnectionProfile().GetConnectionCost();如果(connectionCost.NetworkCostType == NetworkCostType.Unknown||connectionCost.NetworkCostType == NetworkCostType.Unrestricted){//连接成本未知/无限制}别的{//计量网络}参考资料(这里有更详细的答案)1. 如何管理计量网络成本限制 - MSDN2. NetworkCostType 枚举 - MSDN5.管理网络可用性变化要感知网络可用性的重大变化,请使用 NetworkInformation 类的事件NetworkStatusChanged//注册网络状态变化通知networkStatusCallback = new NetworkStatusChangedEventHandler(OnNetworkStatusChange);如果 (!registeredNetworkStatusNotif){NetworkInformation.NetworkStatusChanged += networkStatusCallback;注册网络状态通知=真;}异步无效 OnNetworkStatusChange(对象发送者){//获取当前用于连接互联网的ConnectionProfileConnectionProfile InternetConnectionProfile = NetworkInformation.GetInternetConnectionProfile();如果(InternetConnectionProfile == null){await _cd.RunAsync(CoreDispatcherPriority.Normal, () =>{rootPage.NotifyUser("未连接到 Internet\n", NotifyType.StatusMessage);});}别的{connectionProfileInfo = GetConnectionProfile(InternetConnectionProfile);await _cd.RunAsync(CoreDispatcherPriority.Normal, () =>{rootPage.NotifyUser(connectionProfileInfo, NotifyType.StatusMessage);});}InternetProfileInfo = "";}参考资料检查互联网连接 - developerinsider.co如何管理网络连接事件和可用性变化- MSDN如何检索网络连接信息- MSDN希望对某人有帮助.I would like to check internet connectivity type in Windows Universal Application.Not ConnectedConnected via WLAN(WiFi)Connected via WWAN(Cellular Data)Connected to a metered networkin order to provide an option for downloading large size content. And also sense the significant network availability changes.Currently, I'm only able to check whether internet connected or not using GetIsNetworkAvailable method of NetworkInterface class.NetworkInterface.GetIsNetworkAvailable(); 解决方案 1. Check Internet Connection AvailabilityTo check whether any network connection is established or not use GetIsNetworkAvailable method of NetworkInterface class.bool isNetworkConnected = NetworkInterface.GetIsNetworkAvailable();2. Check Internet Connection Availability via WWLN (WiFi)To check whether internet connected via WWAN use IsWlanConnectionProfile property of ConnectionProfile classConnectionProfile InternetConnectionProfile = NetworkInformation.GetInternetConnectionProfile();bool isWLANConnection = (InternetConnectionProfile == null)?false:InternetConnectionProfile.IsWlanConnectionProfile;3. Check Internet Connection Availability via WWAN (Mobile)To check whether internet connected via WWAN use IsWwanConnectionProfile property ofConnectionProfile classConnectionProfile InternetConnectionProfile = NetworkInformation.GetInternetConnectionProfile();bool isWLANConnection = (InternetConnectionProfile == null)?false:InternetConnectionProfile.IsWwanConnectionProfile;ReferenceHippiehunter Answer4. Check Metered networkTo check whether Internet reachable via a metered connection or not, use GetConnectionCost method on NetworkInterface class. var connectionCost = NetworkInformation.GetInternetConnectionProfile().GetConnectionCost();if (connectionCost.NetworkCostType == NetworkCostType.Unknown || connectionCost.NetworkCostType == NetworkCostType.Unrestricted){ //Connection cost is unknown/unrestricted}else{ //Metered Network}Reference (More detailed answer here)1. How to manage metered network cost constraints - MSDN2. NetworkCostType Enum - MSDN5. Manage network availability changesTo sense the significant network availability changes, use eventNetworkStatusChanged of NetworkInformation class// register for network status change notifications networkStatusCallback = new NetworkStatusChangedEventHandler(OnNetworkStatusChange); if (!registeredNetworkStatusNotif) { NetworkInformation.NetworkStatusChanged += networkStatusCallback; registeredNetworkStatusNotif = true; }async void OnNetworkStatusChange(object sender){ // get the ConnectionProfile that is currently used to connect to the Internet ConnectionProfile InternetConnectionProfile = NetworkInformation.GetInternetConnectionProfile(); if (InternetConnectionProfile == null) { await _cd.RunAsync(CoreDispatcherPriority.Normal, () => { rootPage.NotifyUser("Not connected to Internet\n", NotifyType.StatusMessage); }); } else { connectionProfileInfo = GetConnectionProfile(InternetConnectionProfile); await _cd.RunAsync(CoreDispatcherPriority.Normal, () => { rootPage.NotifyUser(connectionProfileInfo, NotifyType.StatusMessage); }); } internetProfileInfo = "";}ReferencesCheck Internet Connectivity - developerinsider.coHow to manage network connection events and changes in availability - MSDNHow to retrieve network connection information- MSDNHope it helpful to someone. 这篇关于如何在通用 Windows 平台中检查 Internet 连接类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
06-24 06:41