我正在使用chrome.bluetooth Javascript API和PNACL编写Chrome应用程序。我可以打开蓝牙发现,查找设备,连接并成功通信。但我无法弄清楚如何以编程方式从我的应用程序中配对新设备。
这有Windows和Mac系统API; ChromeOS上还有相同的内容吗?
答案 0 :(得分:0)
使用chrome.bluetooth API连接仅适用于OS X,Windows和Chrome操作系统的蓝牙设备。所有函数都通过chrome.runtime.lastError报告失败。
您可以将Chrome应用程序连接到支持RFCOMM或L2CAP服务的任何设备,其中包括市场上的大多数经典蓝牙设备。
如Chrome - Bluetooth中所述,连接设备需要三件事:
bluetoothSocket.create
示例代码实现:
var uuid = '1105';
var onConnectedCallback = function() {
if (chrome.runtime.lastError) {
console.log("Connection failed: " + chrome.runtime.lastError.message);
} else {
// Profile implementation here.
}
};
chrome.bluetoothSocket.create(function(createInfo) {
chrome.bluetoothSocket.connect(createInfo.socketId,
device.address, uuid, onConnectedCallback);
});
请注意,在建立连接之前,您应该使用bluetooth.getDevice
或设备发现API验证适配器是否了解设备。
可以在文档中找到更多信息和示例代码实现。