c# - 检测wlan是否关闭

标签 c# windows-phone-8 .net-4.5 wifi

任何人都可以给我一个提示,如何在 Windows Phone 8.1. 应用程序(不是 8.0!)上以 C# 方式检测 WLAN 是否启用/禁用? 我不想更改这些设置,只是需要知道...

该解决方案是一个 Windows 8.1 通用应用程序,(Windows Phone 8.1) 项目仅引用 .Net 适用于 Windows 应用商店应用Windows Phone 8.1。 按照建议添加C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\WindowsPhone\v8.1\Microsoft.Phone.dll并查询IsWiFiEnabled属性不起作用 - 编译器错误:在 mscorlib.dll 中找不到类型 System.SystemException

谢谢, 马尔赫

最佳答案

如果您正在寻找非 8.1 Silverlight 解决方案:

您可以使用Windows.Networking.Connectivity命名空间来查询。

MSDN NetworkInformation class

帮助您入门的示例

bool is_wifi_enabled = false;
Guid adapter_id = new Guid();

// get the list of connection profiles
// we need the adpater id for the wifi
foreach (var item in NetworkInformation.GetConnectionProfiles())
{

    // check if wifi
    if (item.IsWlanConnectionProfile)
    {
        // tag the adapter
        adapter_id = item.NetworkAdapter.NetworkAdapterId;
    }
}

// get all lan adapters (this most likely will be empty if wlan is disabled)
foreach (var item in NetworkInformation.GetLanIdentifiers())
{
    if (item.NetworkAdapterId == adapter_id)
    {
        is_wifi_enabled = true;
    }
}

关于c# - 检测wlan是否关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26754865/

相关文章:

c# - 是否有一个任务调度程序非常适合在具有超线程的处理器上进行浮点计算?

c# - 判断两个不同的 PropertyInfo 是否来自同一个接口(interface)?

C# XmlSerializer 绑定(bind)失败

c# - 使用 DllImport 将返回的 char* 从 C++ 传递到 C#

c# - 使用UDP接收和处理连续数据包

cordova - 如何使用 phonegap 2.3 在 window phone 8 中退出应用程序

c# - 如何在 LongListSelector SelectedItem 周围创建边框

c# - 如何将 Click 事件处理程序添加到 Windows 手机上的 TextBlock

c# - 如何从 C# 中的 StatusStrip 控件中删除调整大小的抓取器图像?

具有绑定(bind)的 WPF 可见性资源