我正在尝试使用蓝牙低能耗API的Chrome应用。我正在连接设备,获得了运行良好的服务列表。但是,当我遍历服务并调用chrome.bluetoothLowEnergy.getCharacteristics()API时,会出现“权限被拒绝”错误。
我尝试添加发现的服务的UUID。我正在使用128位定制服务和特性。 manifest.json的一部分看起来像这样:
{
"bluetooth": {
"low_energy": true,
"uuids": ["custom 128 bit uuid1", "custom 128 bit uuid2"]
}
}
MyClass.prototype.discoverServices = function(device) {
console.log("Discovering serviecs after timeout");
chrome.bluetoothLowEnergy.getServices(device, function (services) {
console.log("Got services " + services.length);
if (chrome.runtime.lastError) {
console.log(chrome.runtime.lastError.message);
return;
}
services.forEach(function (service) {
console.log("Got service " + service.uuid);
chrome.bluetoothLowEnergy.getCharacteristics(service.instanceId,
function (chrcs) {
if (chrome.runtime.lastError) {
console.log("Failed to get chars for " + service.instanceId + ", error " + chrome.runtime.lastError.message);
return;
}
if (chrcs.length == 0) {
console.log('Service has no characteristics: ' + service.instanceId);
return;
}
chrcs.forEach(function (chrc) {
console.log("Got charachteristic " + chrc.uuid);
});
});
});
});
};
chrome.bluetoothLowEnergy.getCharacteristics()返回“权限被拒绝”错误。我尝试在getServices()API返回的manifest.json中指定确切的128位UUID。但这并不能消除错误。