编写 UWP 应用程序,如果未检测到网络(有线然后无线),我想打开选择无线网络的设置对话框。
我似乎找不到任何关于这样做的可能性的细节,以及如果可能的话,如何实现它。
我不确定这是否完全是你想要的,但它应该可以正常工作。
在 UWP 应用程序中打开 Windows 设置的有用链接是 THIS
正如它所说,如果该应用程序是您使用的移动设备:
ms-settings-wifi:
或者用于桌面/非移动设备
ms-settings:network-wifi
请注意,如果设备上没有无线适配器,
ms-settings:network-wifi
和 ms-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
。