如何获取我的Android蓝牙设备的ID或MAC地址?

赫克托·古铁雷斯

我是Web蓝牙api的初学者,我想获取我的Android蓝牙设备的一些ID或MAC地址...或通过API识别每台设备的某种方式。其实我有这个

// navigator.bluetooth.requestDevice({filters: [{services: ['battery_service']}]})
navigator.bluetooth.requestDevice({acceptAllDevices: true, optionalServices: ['device_information']})
    .then(device => device.gatt.connect())
        .then(server => {
         // Getting device information
            return server.getPrimaryService('device_information');
        })
            .then(service => {
            // Getting serialNumber
                return service.getCharacteristic('serial_number_string');
            })
                .then(characteristic => {
                    // Reading serialNumber
                    return characteristic.readValue();
                })
                    .then(value => {
                        console.log('Serial Number is ' + value.getUint8(0));
                    })
                        .catch(error => {
                            console.log(error);
                        });
文森特·舍布(Vincent Scheib)

您可以使用该BluetoothDevice.id属性来区分两个相似的设备。name如果设备已被命名,也可以使用,例如“ Nexus 6p(鲍勃的)”。这是一个Web蓝牙设备信息示例

您可能会发现这些限制。Web Bluetooth尝试通过对Bluetooth规范的最小更改来以较低的级别公开Bluetooth概念,但确实采取了一些措施来提供与Web相关的安全性和隐私保护。块列表包括:

# org.bluetooth.characteristic.serial_number_string
# Block access to standardized unique identifiers, for privacy reasons.
00002a25-0000-1000-8000-00805f9b34fb

您读取序列号的代码应产生一条控制台消息,将您引导至阻止列表,以获取更多信息。

请参阅规范中与蓝牙设备标识符有关的安全性和隐私性注意事项,以获取有关阻止阻止这些ID的解释。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章