如何在 UWP 应用程序中打开 Wi-Fi 电源?
How to turn on the Wi-Fi Power in a UWP app?
我想在我的 uwp 应用程序中打开 Wi-Fi 电源。
如何打开它?
在 UWP 上,您应该要求用户启用 WiFi。或任何其他设备。
最佳做法是通过 URI Launcehr.
将它们导航到 WiFi 设置以将其打开
await Launcher.LaunchUriAsync(new Uri("ms-settings:network-wifi"));
如果启用了 WiFi,那么您可以从 Windows.Devices.WiFi.WiFiAdapter
访问它。
但在此之前,您必须将所需的设备功能添加到 Package.appxmanifest 文件中 - 右键单击该文件 -> 打开方式 -> XML(文本)编辑器)并添加以下设备功能:
<Capabilities>
<Capability Name="internetClient" />
<!-- Add the capability here -->
<DeviceCapability Name="wifiControl" />
</Capabilities>
然后您可以像这样以编程方式访问 WiFi 适配器:
var access = await Windows.Devices.WiFi.WiFiAdapter.RequestAccessAsync();
if(access == Windows.Devices.WiFi.WiFiAccessStatus.Allowed)
{
var result = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(
Windows.Devices.WiFi.WiFiAdapter.GetDeviceSelector());
if(result.Count >= 1)
{
Windows.Devices.WiFi.WiFiAdapter firstAdapter =
await Windows.Devices.WiFi.WiFiAdapter.FromIdAsync(result[0].Id);
await firstAdapter.ScanAsync();
}
}
更多:here.
一般来说,UWP 应用程序无权更改全局设置或可能会干扰其他 运行 应用程序的设置。如果您想检测网络状态,您可以使用 class NetworkInformation 来实现。设备无线电的控制权可供 OEM 和运营商使用,但不适用于其他开发人员。
也就是说,对于那些有权访问 WiFiAdapter class allows for all the WiFi adapters in the device to be enumerated and programmatically connected or disconnected. The adapters are enumerated with FindAllAdaptersAsync. Calling this method requires the wifiControl capability. There are some other radio related capabilities in the namespace Windows.Devices.Radios 的人。
根据您用于开发的帐户类型,对某些 API 的访问受到限制。有关详细信息,请参阅 Microsoft 的 documentation on Account Types。
我想在我的 uwp 应用程序中打开 Wi-Fi 电源。 如何打开它?
在 UWP 上,您应该要求用户启用 WiFi。或任何其他设备。 最佳做法是通过 URI Launcehr.
将它们导航到 WiFi 设置以将其打开await Launcher.LaunchUriAsync(new Uri("ms-settings:network-wifi"));
如果启用了 WiFi,那么您可以从 Windows.Devices.WiFi.WiFiAdapter
访问它。
但在此之前,您必须将所需的设备功能添加到 Package.appxmanifest 文件中 - 右键单击该文件 -> 打开方式 -> XML(文本)编辑器)并添加以下设备功能:
<Capabilities>
<Capability Name="internetClient" />
<!-- Add the capability here -->
<DeviceCapability Name="wifiControl" />
</Capabilities>
然后您可以像这样以编程方式访问 WiFi 适配器:
var access = await Windows.Devices.WiFi.WiFiAdapter.RequestAccessAsync();
if(access == Windows.Devices.WiFi.WiFiAccessStatus.Allowed)
{
var result = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(
Windows.Devices.WiFi.WiFiAdapter.GetDeviceSelector());
if(result.Count >= 1)
{
Windows.Devices.WiFi.WiFiAdapter firstAdapter =
await Windows.Devices.WiFi.WiFiAdapter.FromIdAsync(result[0].Id);
await firstAdapter.ScanAsync();
}
}
更多:here.
一般来说,UWP 应用程序无权更改全局设置或可能会干扰其他 运行 应用程序的设置。如果您想检测网络状态,您可以使用 class NetworkInformation 来实现。设备无线电的控制权可供 OEM 和运营商使用,但不适用于其他开发人员。
也就是说,对于那些有权访问 WiFiAdapter class allows for all the WiFi adapters in the device to be enumerated and programmatically connected or disconnected. The adapters are enumerated with FindAllAdaptersAsync. Calling this method requires the wifiControl capability. There are some other radio related capabilities in the namespace Windows.Devices.Radios 的人。
根据您用于开发的帐户类型,对某些 API 的访问受到限制。有关详细信息,请参阅 Microsoft 的 documentation on Account Types。