2

我正在 Android 中设置蓝牙 LE GATT 服务器,并希望在 Chrome 中使用 Web 蓝牙 API 作为 GATT 客户端来检查它是否正常工作。实际上,这是我稍后在 Android 中构建 FIDO Authenticator 的第一步。

首先,我尝试将我的服务的 uuid 设置0000fffd-0000-1000-8000-00805f9b34fb在我的 Android 应用程序中。像这样的东西:

// start gatt server

bluetoothGattServer = bluetoothManager.openGattServer(this, callback);
bluetoothGattServer.addService(
new BluetoothGattService(UUID.fromString("0000fffd-0000-1000-8000-00805f9b34fb"),
BluetoothGattService.SERVICE_TYPE_PRIMARY));

// start advertising
// ...

然后,我在 Chrome 中执行了以下 Javascript 代码来检查是否可以建立连接。

navigator.bluetooth.requestDevice({ 
filters: [{ services: ['0000fffd-0000-1000-8000-00805f9b34fb'] }] })
.then(device => { console.log(device); })
.catch(error => { console.log(error); });

但是,我只得到了如下异常

DOMException

当我将 uuid 更改为另一个,例如62893031-5e68-4a71-94e4-01fb81f16818在我的 Android 代码中时,它就起作用了!(我的意思是它能够连接到我的手机,我可以在 Chrome 的控制台中看到我的设备信息)

我不知道到底是什么问题。我以前的 uuid 有什么问题?如何调试它以了解根本原因?

感谢您的检查!

4

1 回答 1

2

你可以试试

console.log(error.messsage);

代替

console.log(error);

你会看见

requestDevice() 使用包含被阻止的 UUID 的过滤器调用。 https://webbluetoothcg.github.io/web-bluetooth/#attacks-on-devices

检查它以查看安全原因。

于 2019-06-01T09:59:42.520 回答