【发布时间】:2016-07-29 21:46:50
【问题描述】:
我正在尝试创建一个 chrome 应用程序,该应用程序会在某个蓝牙设备发送数据时显示。具体来说,我有 2 只蓝牙鼠标,我想确定哪只在特定时间被移动。 我遵循了 Chrome 开发文档并取得了成功,直到我尝试在接收时添加一个侦听器以查看来自设备的数据。我收到“无法读取未定义的属性‘addListener’”错误。
这是我开始收到此错误的时间: Error message
这是我正在使用的代码
chrome.bluetooth.getDevices(function(devices) {
for (var i = 0; i < devices.length; i++) {
//Displaying device names
console.log(i+": "+devices[i].name);
}
//uuid for a specific device
var uuid = "00001200-0000-1000-8000-00805f9b34fb";
// var uuid = devices[4].uuid;
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,
devices[4].address, uuid, onConnectedCallback);
console.log(createInfo);
chrome.bluetoothSocket.onRecieve.addListener(function(receiveInfo) {
if (receiveInfo.socketId != socketId)
return;
console.log(receiveInfo);
});
});
});
【问题讨论】:
标签: javascript api google-chrome bluetooth google-chrome-app