Ошибка отказа в доступе для API chrome.bluetoothLowEnergy.getCharacteristics () - PullRequest
0 голосов
/ 30 сентября 2019

Я испытываю приложение Chrome, которое использует API-интерфейсы Bluetooth с низким энергопотреблением. Я подключаюсь к устройствам, получаю список сервисов, который работает нормально. Но когда я перебираю сервисы и вызываю API chrome.bluetoothLowEnergy.getCharacteristics (), я получаю сообщение об ошибке «Отказано в доступе».

Я попытался добавить 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 () возвращает ошибку «Отказано в доступе». Я попытался указать точные 128-битные UUID в файле manifest.json, которые возвращает API getServices (). Но это не устранило ошибку.

...