- 我有一个代码列出Windows Phone 8.1可以检测到的所有BluetoothLE设备(配对和未配对):
var devices = await DeviceInformation.FindAllAsync( BluetoothLEDevice.GetDeviceSelector() );
foreach ( DeviceInformation di in devices )
{
BluetoothLEDevice bleDevice = await BluetoothLEDevice.FromIdAsync( di.Id );
Debug.WriteLine( bleDevice.Name );
}
但是,行:
var devices = await DeviceInformation.FindAllAsync( BluetoothLEDevice.GetDeviceSelector() );
抛出异常 .
Any Idea why?
- 我也试过这段代码:
var devices = await DeviceInformation.FindAllAsync(GattDeviceService.GetDeviceSelectorFromUuid(GattServiceUuids.GenericAttribute));
此代码不会引发异常,但会返回0个设备 .
Any Idea why?
在这两种情况下,DeviceCapability定义如下:
<m2:DeviceCapability Name="bluetooth.genericAttributeProfile">
<m2:Device Id="any">
<m2:Function Type="name:genericAttribute"/>
</m2:Device>
</m2:DeviceCapability>
1 回答
如果您使用的是Windows Phone 8.1,则无法枚举未配对的设备 . 这与Windows 10 SDK 1511版本有所不同