我想扫描并列出可用的WIFI访问点,并允许用户从Windows应用商店应用的自定义界面连接到一个。
我知道WiFi原生API,但在Windows商店App中无法访问。
我可以使用WifiDirect API吗?
答案 0 :(得分:1)
对于Windows 8.1:
最适合在Windows 8.1上使用WiFi Direct。您的设备必须支持Wifi Direct。 “您可以使用Wi-Fi Direct来枚举无线范围内的Wi-Fi Direct设备列表,然后使用Wi-Fi Direct设备在应用之间建立套接字连接。” 在此处查看完整示例: 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);
}