如何在不使用设置应用程序的情况下在 Windows 10 平板电脑应用程序中发现未配对的蓝牙设备

How to discover unpaired Bluetooth devices in a Windows 10 tablet application without using the settings app

我想知道是否可以在 Windows 10 平板电脑应用程序中以编程方式发现未配对的蓝牙设备。

我真的不想通过 设置 -> 设备 -> 蓝牙 进行配对。

很遗憾,我找不到任何 documentation/example 有帮助的东西。

我尝试使用 BluetoothLEAdvertisementWatcher 搜索蓝牙设备,但找不到任何设备。可能是因为这些设备不是 BluetoothLE 设备。认为这些是兼容的。

我还认为可以创建一个 CLI/C++ 包装器,我可以在我的 UWP 应用程序中重用它,但我对此感到非常不确定,因为它不是全部(尤其是接口部分) Win32 API 可在 UWP 环境中重复使用。

在最后一个选项中,我认为必须有一种方法可以在输入 设置 -> 设备 -> 蓝牙 时获取 Windows 生成的设备列表,并且我试图通过使用 DeviceWachter 来实现这一点,但没有成功。

现在我很绝望。对于我的应用程序,在使用之前手动配对每台设备会很糟糕。我不明白为什么微软会削减开发人员的数量。

在此先感谢您的帮助。

I wonder if it is possible to discover unpaired Bluetooth devices programmatically within a Windows 10 tablet application.

是的,有可能。

I tried to search for Bluetooth devices by using the BluetoothLEAdvertisementWatcher but I wasn't able to find any. Probably because these devices were no BluetoothLE devices.

你用错了watcher。你需要的是DeviceWatcher, not BluetoothLEAdvertisementWatcher。它们之间的区别在于 DeviceWatcher 用于动态枚举设备,而 BluetoothLEAdvertisementWatcher 用于接收蓝牙低功耗 (LE) 广告。

官方有Device enumeration and pairing sample,你可以参考这个sample的场景8,这个sample绝对是你需要的。

Grace 的回答是正确的。我之前尝试过这个示例,但停止了它的工作,因为它期望 Windows Phone 而不是 Windows 10 平板电脑。

现在我提取了 DeviceWatcher 部分,但使用选择器 BluetoothDevice.GetDeviceSelectorFromPairingState(false) 创建了 DeviceWatcher。只有使用这个选择器,观察者才能找到未配对的蓝牙设备。

它也适用于:

DeviceInformation.FindAllAsync(BluetoothDevice.GetDeviceSelectorFromPairingState(false))