如何知道Cordova中的蓝牙设备类型

时间:2020-01-02 05:17:05

标签: javascript cordova bluetooth

我正在使用cordova plugin来显示所有蓝牙设备的列表。但是我需要过滤掉所有打印机设备。我该怎么办?无论如何,我可以通过其Mac地址或名称找到蓝牙设备的类型吗?

1 个答案:

答案 0 :(得分:0)

如您所提到的文档所述。

var device_names = {};
var updateDeviceName = function (device) {
    device_names[device.address] = device.name;
};

// Add listener to receive newly found devices
networking.bluetooth.onDeviceAdded.addListener(updateDeviceName);

// With the listener in place, get the list of known devices
networking.bluetooth.getDevices(function (devices) {
    for (var i = 0; i < devices.length; i++) {
        updateDeviceName(devices[i]);
    }
});

// Now begin the discovery process.
networking.bluetooth.startDiscovery(function () {
    // Stop discovery after 30 seconds.
    setTimeout(function () {
        networking.bluetooth.stopDiscovery();
    }, 30000);
});

在这里签出:Device information and discovery