【发布时间】:2016-09-10 15:02:04
【问题描述】:
编写 UWP 应用,如果未检测到网络(有线然后无线),我想调出选择无线网络的设置对话框。
我似乎找不到任何关于这样做的可能性的细节,以及如果可能的话,如何做到这一点。
【问题讨论】:
标签: c# network-programming wireless uwp
编写 UWP 应用,如果未检测到网络(有线然后无线),我想调出选择无线网络的设置对话框。
我似乎找不到任何关于这样做的可能性的细节,以及如果可能的话,如何做到这一点。
【问题讨论】:
标签: c# network-programming wireless uwp
我不确定这是否完全是您想要的,但它应该可以正常工作。
在 UWP 应用中打开窗口设置的有用链接是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
}
}
【讨论】:
Process.Start了...Launcher.LaunchUriAsync是要走的路。
给你:
var profile = NetworkInformation.GetInternetConnectionProfile();
if (profile == null || profile.GetNetworkConnectivityLevel() < NetworkConnectivityLevel.InternetAccess)
{
await Launcher.LaunchUriAsync(new Uri("ms-settings:network-wifi"));
}
这样,当有互联网访问或受限互联网访问时,网络设置就会打开。要仅捕获丢失的 Internet 访问权限,请将比较从 < NetworkConnectivityLevel.InternetAccess 更改为 != NetworkConnectivityLevel.InternetAccess。
【讨论】: