bluetooth - 网络蓝牙 : Want to exclude certain devices when using navigator. bluetooth.requestDevice

标签 bluetooth bluetooth-lowenergy web-bluetooth

我有一个数组,其中包含一些我不想在执行 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/

相关文章:

Android BLE 连接和断开快速读取 1 个特征。一些BLE设备在快速连接断开后停止广播

c# - 低功耗蓝牙扫描仪 Xamarin Android

javascript - 无法收到在 Web 蓝牙 API 中工作的通知

javascript - 记住设备并重新连接

java - Android蓝牙周期性调用inputStream和outputStream : inconsistent timestamps

android - 从文档中启用 Android 蓝牙

Android 外部摄像头选项 - 覆盖在视频流之上,没有中间人服务器/路由器

javascript - 我可以将蓝牙连接构建到 HTML5/JS WebAPP 中吗

web-bluetooth - 是否可以在浏览器刷新时保持蓝牙 LE 连接

javascript - 忘记已配对的设备 - 网络蓝牙