我有一个数组,其中包含一些我不想在执行 navigator.bluetooth.requestDevice 时获取的设备的名称
有没有办法像按名称过滤设备一样将它们排除在外?
navigator.bluetooth.requestDevice({ 过滤器: [ { namePrefix: "SPDCM", }, ], 可选服务: [UUID_FOTA_SERVICE] })
最佳答案
Chrome 114 navigator.bluetooth.requestDevice()
中有新的 "exclusionFilters"
选项,允许 Web 开发人员从浏览器选择器中排除某些设备。它可用于排除与更广泛的过滤器匹配但不受支持的设备。
// Request access to a bluetooth device whose name starts with "Created by".
// The device named "Created by Francois" has been reported as unsupported.
const device = await navigator.bluetooth.requestDevice({
filters: [{ namePrefix: "Created by" }],
exclusionFilters: [{ name: "Created by Francois" }],
});
您可以通过 https://googlechrome.github.io/samples/web-bluetooth/exclusion-filters.html 来玩它
资源:
关于bluetooth - 网络蓝牙 : Want to exclude certain devices when using navigator. bluetooth.requestDevice,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75815353/