检测WLAN是否关闭

检测WLAN是否关闭

问题描述:

有人可以给我一个提示,如果启用/禁用了WLAN,如何在Windows Phone 8.1。 App(不是8.0!)上以C#方式进行检测?
我不想更改这些设置,只需要知道...

can anybody give me a hint, how to programmatically detect in C# on Windows Phone 8.1. App (not 8.0!), if the WLAN is enabled / disabled? I don't want to change these settings, just need to know...

该解决方案是Windows 8.1通用应用程序,而(Windows Phone 8.1)项目仅引用
.Net用于Windows Store Apps Windows Phone 8.1
根据建议添加 C:\程序文件(x86)\参考程序集\Microsoft\Framework\WindowsPhone\v8.1\Microsoft.Phone.dll ,查询 IsWiFiEnabled 属性不起作用
-编译器错误:mscorlib.dll中找不到类型System.SystemException

The Solution is a Windows 8.1 universal app, and the (Windows Phone 8.1) project just references .Net for Windows Store Apps and Windows Phone 8.1. Adding the C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\WindowsPhone\v8.1\Microsoft.Phone.dll as suggested and querying the IsWiFiEnabled property does not work - Compiler error: Cannot find type System.SystemException in mscorlib.dll

谢谢,
Marher

Thanks, Marher

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

If you're looking for a Non 8.1 Silverlight solution:

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

You can use the Windows.Networking.Connectivity namespace to query this.

MSDN NetworkInformation类

一个入门示例

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;
    }
}