我如何获取 wifi AP 列表并从 Windows 商店应用程序连接到一个 AP

How do i get list of wifi AP and connect to one AP from Windows store app

我想扫描并列出可用的 WIFI 接入点,并允许用户从 Windows 商店应用程序上的自定义界面连接到一个接入点。

我知道 WiFi 本机 API,但这在 Windows 商店应用程序中无法访问。

我可以使用 WifiDirect API 吗?

对于Windows 8.1:

最好在 Windows 8.1 上使用 WiFi Direct。您的设备必须支持 Wifi Direct。 "You can use Wi-Fi Direct to both enumerate a list of Wi-Fi Direct devices within wireless range, and then set up a socket connection between apps using Wi-Fi Direct devices." 在此处查看完整示例: https://code.msdn.microsoft.com/windowsapps/WiFiDirectDevice-sample-59a6e5e0#content

对于Windows 10: 您可以使用 Windows.Devices.WiFi.WiFiAdapter 在 Windows 商店应用程序中执行此操作。 确保在应用程序清单中设置功能:

 <DeviceCapability Name="wiFiControl" />

这里有一个代码示例,它基本上可以解决问题,只需连接到具有 ssid "MyNetworkSSID" 的网络即可。

using Windows.Devices.WiFi;


    var access = await WiFiAdapter.RequestAccessAsync();
    var result = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(WiFiAdapter.GetDeviceSelector());
    if (result.Count >= 1)
    {
// take first adapter
    nwAdapter = await WiFiAdapter.FromIdAsync(result[0].Id);
// scan for networks
    await nwAdapter.ScanAsync();
// find network with the correct SSID
var nw = nwAdapter.NetworkReport.AvailableNetworks.Where(y => y.Ssid.ToLower() == "MyNetworkSSID").FirstOrDefault();
// connect 
    await nwAdapter.ConnectAsync(nw, WiFiReconnectionKind.Automatic);
   }