检测wlan是否已关闭

时间:2014-11-05 10:28:17

标签: c# windows-phone-8 .net-4.5 wlan

任何人都可以给我一个提示,如果WLAN启用/禁用,如何在Windows Phone 8.1。 App(不是8.0!)上以C#编程检测? 我不想改变这些设置,只需知道......

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

谢谢, Marher

2 个答案:

答案 0 :(得分:1)

如果您正在寻找Non 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;
    }
}

答案 1 :(得分:0)

使用DeviceNetworkInformation class

IsWiFiEnabled属性

如果您需要其他网络信息,可以参考How-To network information page

问候。

相关问题