最近发现Community Toolkit有了网络辅助类,貌似很早就有了。。。

很不错,还是用。给大家分享一下。

1. 检测网络是否可用

2. 检测网络是否是计费模式?

3. 检测网络接入类型

4. 信号强度

5. 网络名称

 

UWP 检测网络状态

 

 

至于代码嘛,就很简单啦

                IsInternetAvailableText.Text = NetworkHelper.Instance.ConnectionInformation.IsInternetAvailable ? "Yes" : "No";
                IsInternetOnMeteredConnectionText.Text = NetworkHelper.Instance.ConnectionInformation.IsInternetOnMeteredConnection ? "Yes" : "No";
                ConnectionTypeText.Text = NetworkHelper.Instance.ConnectionInformation.ConnectionType.ToString();
                SignalBarsText.Text = NetworkHelper.Instance.ConnectionInformation.SignalStrength.GetValueOrDefault(0).ToString();
                NetworkNamesText.Text = string.Join(", ", NetworkHelper.Instance.ConnectionInformation.NetworkNames);

 

 

别忘了引用 using Microsoft.Toolkit.Uwp.Connectivity;

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-28
  • 2021-10-14
  • 2022-12-23
  • 2021-05-30
  • 2022-02-11
  • 2022-02-03
猜你喜欢
  • 2021-09-04
  • 2021-07-23
  • 2021-09-26
  • 2022-02-07
  • 2022-02-11
相关资源
相似解决方案