【问题标题】:Bring up a WiFi dialog if network not present如果网络不存在,则显示 WiFi 对话框
【发布时间】:2016-09-10 15:02:04
【问题描述】:

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

我似乎找不到任何关于这样做的可能性的细节,以及如果可能的话,如何做到这一点。

【问题讨论】:

    标签: c# network-programming wireless uwp


    【解决方案1】:

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

    在 UWP 应用中打开窗口设置的有用链接是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
       }
    }
    

    【讨论】:

    • 没有Process.Start了...Launcher.LaunchUriAsync是要走的路。
    【解决方案2】:

    给你:

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

    这样,当有互联网访问或受限互联网访问时,网络设置就会打开。要仅捕获丢失的 Internet 访问权限,请将比较从 &lt; NetworkConnectivityLevel.InternetAccess 更改为 != NetworkConnectivityLevel.InternetAccess

    【讨论】:

    • 完美答案!正是我正在寻找的。有配置文件调用,不清楚如何运行该对话框。再次感谢!
    • 谢谢 :) 如果您能将我的帖子标记为答案,如果它真的有帮助,我将不胜感激。
    猜你喜欢
    • 2014-10-17
    • 2021-12-28
    • 1970-01-01
    • 1970-01-01
    • 2022-12-06
    • 1970-01-01
    • 2019-12-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多