UWP BluetoothLEDevice“未找到元素。(HRESULT异常:0x80070490)”

时间:2016-01-14 14:03:48

标签: c# bluetooth async-await bluetooth-lowenergy uwp

我需要BluetoothLEDevice才能通过GATT连接。 这是我能想到的一个简单的新通用应用程序中最简单的代码:

protected async override void OnNavigatedTo(NavigationEventArgs e)
{
    base.OnNavigatedTo(e);

    var devices = await DeviceInformation.FindAllAsync(BluetoothLEDevice.GetDeviceSelector());
    if (devices.Count <= 0) return;
    this.bluetoothDevice = await BluetoothLEDevice.FromIdAsync(devices[0].Id);
}

方法BluetoothLEDevice.FromIdAsync始终抛出异常: “未找到元素。(HRESULT异常:0x80070490)”

如果它可能与设备功能有关,我很好。 我在appmanifest中的设备功能如下所示:

<Capabilities>
  <Capability Name="internetClient" />
    <DeviceCapability Name="bluetooth.genericAttributeProfile">
    <Device Id="any">
      <Function Type="name:genericAttribute"/>
    </Device>
  </DeviceCapability>
</Capabilities>

我也试过这些方法来获取设备:

var devices = await DeviceInformation.FindAllAsync(GattDeviceService.GetDeviceSelectorFromUuid(new Guid("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX")));

var devices = await DeviceInformation.FindAllAsync(GattDeviceService.GetDeviceSelectorFromUuid(GattServiceUuids.GenericAccess));

每个方法都返回一个包含2个配对的BluetoothLE设备的列表。 然而,第一种方法(BluetoothLEDevice.GetDeviceSelector())返回具有空名称字段的设备,而它们具有正确的名称和其他2种方法。

我在任何地方都找不到任何相同问题的例子,在使用“BluetoothLEDevice.FromIdAsync”时,似乎没有人关心异常处理。

0 个答案:

没有答案
相关问题