当前位置: 首页 > 编程语言 > C#

Windows10UWP——检测当前网络连接是Wifi还是Cellular?

时间:2023-04-10 21:39:45 C#

Windows10UWP-检测当前互联网连接是Wifi还是蜂窝网络?在Windows10UWP应用程序中,如何检测当前Internet连接是Wifi还是Cellular?在UWP中,您可以使用IsWlanConnectionProfile或IsWwanConnectionProfile属性检查网络连接。一个例子是:vartemp=Windows.Networking.Connectivity.NetworkInformation.GetInternetConnectionProfile();if(temp.IsWlanConnectionProfile){//itswireless}elseif(temp.IsWwanConnectionProfile){//itsmobile}我希望这会有所帮助。除了获得连接(正如其他人所提到的),您还可以更好地处理按流量计费的连接。如何管理计量网络成本约束开关(connectionCost.NetworkCostType){caseNetworkCostType.Unrestricted://break;caseNetworkCostType.Fixed://中断;caseNetworkCostType.Variable://中断;caseNetworkCostType.Unknown://中断;默认://中断;请参阅GitHub上的网络演示。以上是C#学习教程:Windows10UWP-DetectthecurrentInternetconnectionwhetherthecurrentInternetconnectionisWifiorCellular?如果分享的内容对你有用,需要了解更多C#学习教程,希望你多多关注——if(connectionCost.Roaming||connectionCost.OverDataLimit){Cost=NetworkCost.OptIn;原因=connectionCost.Roaming?“连接正在漫游;使用连接可能会产生额外费用。”:"连接已超过使用上限。";}elseif(connectionCost.NetworkCostType==NetworkCostType.Fixed||connectionCost.NetworkCostType==NetworkCostType.Variable){Cost=NetworkCost.Conservative;原因=connectionCost.NetworkCostType==NetworkCostType.Fixed?“连接的允许使用有限。”:"连接是根据使用情况收费的。";}else{Cost=NetworkCost.Normal;原因=连接成本。NetworkCostType==NetworkCostType.Unknown?"Connectionisunknown":"连接成本不受限制";}本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处: