如果网络不存在,请弹出WiFi对话框

本文关键字:WiFi 对话框 网络 不存在 如果 | 更新日期: 2023-09-27 18:18:12

编写一个UWP应用程序,如果没有检测到网络(有线然后无线),我想打开选择无线网络的设置对话框。

我似乎找不到这样做的可能性的任何细节,如果可能的话,如何使它发生

如果网络不存在,请弹出WiFi对话框

我不确定这是否完全是你想要的,但它应该工作良好。

在UWP应用程序中打开windows设置的一个有用链接是THIS

如果应用程序是您使用的移动设备:ms-settings-wifi:

或者对于桌面/非移动设备使用ms-settings:network-wifi

注意,ms-settings:network-wifims-settings-wifi:打开主设置窗口,如果设备上没有无线适配器。

尝试在运行(Win+R)中启动此应用程序ms-settings:network-wifi

在c#中使用这个的一个例子是

// The URI to launch
string uriToLaunch = @"ms-settings:network-wifi";
// Create a Uri object from a URI string 
var uri = new Uri(uriToLaunch);
// Launch the URI
async void DefaultLaunch()
{
   // Launch the URI
   var success = await Windows.System.Launcher.LaunchUriAsync(uri);
   if (success)
   {
      // URI launched
   }
   else
   {
      // URI launch failed
   }
}

给你:

var profile = NetworkInformation.GetInternetConnectionProfile();
if (profile == null || profile.GetNetworkConnectivityLevel() < NetworkConnectivityLevel.InternetAccess)
{
    await Launcher.LaunchUriAsync(new Uri("ms-settings:network-wifi"));
}

这样,当有互联网接入或受限制的互联网接入时,网络设置就会打开。为了只捕获缺失的互联网访问,将比较从< NetworkConnectivityLevel.InternetAccess更改为!= NetworkConnectivityLevel.InternetAccess