[英]detect if wlan is turned off
can anybody give me a hint, how to programmatically detect in C# on Windows Phone 8.1. 谁能给我一个提示,如何在Windows Phone 8.1上以编程方式在C#中进行检测。 App (not 8.0!), if the WLAN is enabled / disabled?
应用程序(不是8.0!),是否启用/禁用了WLAN? I don't want to change these settings, just need to know...
我不想更改这些设置,只需要知道...
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 . 该解决方案是Windows 8.1通用应用程序,并且(Windows Phone 8.1)项目仅引用.Net用于Windows Store Apps和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
根据建议添加C:\\ Program Files(x86)\\ Reference Assemblies \\ Microsoft \\ Framework \\ WindowsPhone \\ v8.1 \\ Microsoft.Phone.dll并查询IsWiFiEnabled属性不起作用-编译器错误:在以下位置找不到类型System.SystemException mscorlib.dll中
Thanks, Marher 谢谢,Marher
If you're looking for a Non 8.1 Silverlight solution: 如果您正在寻找非8.1 Silverlight解决方案:
You can use the Windows.Networking.Connectivity
namespace to query this. 您可以使用
Windows.Networking.Connectivity
命名空间进行查询。
MSDN NetworkInformation class MSDN NetworkInformation类
An example to get you started 一个入门的例子
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;
}
}
Use the IsWiFiEnabled
property of DeviceNetworkInformation class 使用DeviceNetworkInformation类的
IsWiFiEnabled
属性
You can refer to the How-To network information page if you need other network informations. 如果您需要其他网络信息,可以参考“操作方法”网络信息页面 。
Regards. 问候。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.