我正在使用chrome.bluetooth Javascript和PNACL编写一个Chrome。我可以打开蓝牙发现,找到设备,连接,并成功地进行交流。但我不知道如何从我的应用程序中编程地配对一台新设备。
这方面有Windows和Mac;在ChromeOS上是否存在相同的API?
发布于 2016-05-03 09:47:57
使用chrome.bluetooth API连接到只在OS、Windows和Chrome上工作的蓝牙设备。所有函数都通过chrome.runtime.lastError报告故障。
您可以让您的铬应用程序连接到任何设备,支持RFCOMM或L2CAP服务,其中包括市场上的大多数经典蓝牙设备。
正如Chrome蓝牙中详细介绍的那样,连接到设备需要做三件事:
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来验证适配器是否知道设备。
更多信息和示例代码实现可以在文档中找到。
https://stackoverflow.com/questions/36991499
复制相似问题