检测 wlan 是否关闭 [英] detect if wlan is turned off
问题描述
谁能给我一个提示,如果启用/禁用 WLAN,如何在 Windows Phone 8.1. 应用程序(不是 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 for Windows Store Apps 和 Windows Phone 8.1.按照建议添加 C:Program Files (x86)Reference AssembliesMicrosoftFrameworkWindowsPhonev8.1Microsoft.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 AssembliesMicrosoftFrameworkWindowsPhonev8.1Microsoft.Phone.dll as suggested and querying the IsWiFiEnabled property does not work - Compiler error: Cannot find type System.SystemException in mscorlib.dll
谢谢,马赫
推荐答案
如果您正在寻找非 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.
一个让你入门的例子
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;
}
}
这篇关于检测 wlan 是否关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!