google-chrome - 覆盖 navigator.bluetooth.requestDevice() 的默认行为
问题描述
当我调用 navigator.bluetooth.requestDevice({acceptAllDevices: true}) 时,会弹出一个带有我周围设备的 chrome 窗口。我只能在这里选择 1 个设备。有没有办法选择多个设备或不弹出此窗口;我可以实现我自己的基于 Web 的窗口来显示我周围的 BLE 设备吗?
navigator.bluetooth.requestDevice({acceptAllDevices: true})
.then(device => {
console.log(device);
});
解决方案
新的navigator.bluetooth.getDevices
API(在 Chrome 85 及更高版本中)实际上允许您避免此提示,如果您以前用于requestDevice
配对设备。
它上面的 chromestatus 页面在这里:https ://www.chromestatus.com/feature/4797798639730688
它包含指向开发人员指南的链接。
最简单的hackiest用法是:
navigator.bluetooth.getDevices().then(function(devices) {
if (devices.length==0) put_up_button_for_requestDevice();
else return devices[0].gatt.connect();
}).then(finish_connecting_as_normal)
推荐阅读
- javascript - 使用 chrome 扩展名操作网站的 javascript 功能
- ssl - 叶证书上的证书链验证失败
- android - 在android studio中隐藏整个底部导航栏的问题
- sql - SQL 将月份数据拆分为天日期行
- python - 如何使用 Threading 同时运行 discord 客户端和 pygame?
- javascript - 具有块颜色属性的滚动动画不起作用
- fastreport - 在 FastReport4 中的交互式报表上单击 Object1 时更改 Object2
- java - Flutter 报错 Kotlin 找不到所需的 JDK 工具
- azure-devops - Azure DevOps 自托管管道代理无法连接到服务器
- c# - “解析值时遇到意外字符:[。” 反序列化为列表时出现异常
场地