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

Bring up a WiFi dialog if network not present

正在编写 UWP 应用程序,如果未检测到网络(有线然后无线),我想调出选择无线网络的设置对话框。

我似乎找不到任何关于这样做的可能性的细节,如果可能的话,如何实现它。

我不确定这是否完全是您想要的,但它应该可以正常工作。

在 UWP 应用程序中打开 windows 设置的有用 link 是 THIS

如果该应用是您使用的手机,它会说:ms-settings-wifi:

或者对于 Desktop/Non-Mobile 设备使用 ms-settings:network-wifi

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

尝试在 运行 (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