bluetooth - 网络蓝牙:想要在使用 navigator.bluetooth.requestDevice 时过滤制造商数据
问题描述
我看到谷歌浏览器没有对制造商数据实施过滤。问题707635,似乎没有任何进展。
使用 navigator.bluetooth.requestDevice (https://webbluetoothcg.github.io/web-bluetooth/#example-filter-by-manufacturer-service-data时,Web 蓝牙规范有一个(不稳定的)规范用于过滤制造商数据
有谁知道这方面是否有任何进展或使这种过滤工作?
解决方案
根据我们的讨论,我在 Chrome 92 的 Web 蓝牙中添加了对制造商数据过滤器的支持。请参阅https://crbug.com/707635
这是一个例子:
// Filter Bluetooth devices from Google company with manufacturer data bytes
// that start with [0x01, 0x02].
navigator.bluetooth.requestDevice({
filters: [{
manufacturerData: [{
companyIdentifier: 0x00e0,
dataPrefix: new Uint8Array([0x01, 0x02])
}]
}],
optionalServices: ['battery_service'] // Required to access service later.
})
.then(device => { /* … */ })
.catch(error => { console.error(error); });
您可以在 https://googlechrome.github.io/samples/web-bluetooth/manufacturer-data-filter.html 找到一个示例,在https://web.dev/bluetooth/#manufacturer-data-找到一些开发人员文档筛选
让我知道这是否适合你;)
推荐阅读
- java - 如何使用opencsv正确处理带引号的字符串中的逗号?
- git - 如何使父 repo 分支指向子模块 repo 分支
- c++ - Visual Studio 中的 LNK2001 和 LNK2019 错误有什么区别?
- encryption - 在 .Net 5 中通过 X509Certificate2Collection.Export() 创建 PKCS12 文件时使用什么加密算法加密私钥?
- r - r中的条件字符串替换
- max - quicksight中获取os版本列的最大值
- github - 部署时删除的文件
- java - 爪哇。难以从对象调用方法。(初学者)
- git - Github git push origin main 不起作用
- c++ - 没有调用 Dllmain 函数