c# - 如何使用 DeviceInformation.FindAllAsync 枚举 Windows Phone 可见的所有 BLE 设备?

标签 c# bluetooth windows-phone-8.1 winrt-xaml

  1. 我有一个代码可以列出 Windows Phone 8.1 可以检测到的所有蓝牙LE 设备(已配对和未配对):

        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() );

抛出异常。

知道为什么吗?

  1. 我也试过这段代码:

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

此代码不会抛出异常,但会返回 0 个设备。

知道为什么吗?

在这两种情况下,DeviceCapability 定义如下:

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

最佳答案

如果您使用的是 Windows Phone 8.1,则无法枚举未配对的设备。这随 Windows 10 SDK 版本 1511 而改变

关于c# - 如何使用 DeviceInformation.FindAllAsync 枚举 Windows Phone 可见的所有 BLE 设备?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34732969/

相关文章:

c# - 每个频率的响度相等

c# - NHibernate 没有获取更改

ios - 游戏套件和 iPhone

c# - 如何在 Windows Phone 运行时获取 StorageFolder 中的所有文件?

c# - 使用 IComparer 随机播放

c# - 远程对象上的 DynamicInvoke 是否异步工作?

c# - 尝试执行 Microsoft Band 示例代码时出错

android - 16 个蓝牙振动器连接到 Android 手机

windows-phone-8.1 - 无法将通用应用程序部署到Windows Phone 10技术预览版

c# - 在 Windows Phone 8.1 运行时读取项目文件夹中的文本文件