Nativescript 蓝牙搜索

Nativescript Bluetooth searching

我正在尝试使用此插件搜索蓝牙设备:

https://github.com/nativescript-community/ble

我每次都尝试使用以下代码搜索设备:

doStartScanning(){
        {
            this.isLoading = true;
            // reset the array
            this.observablePeripheralArray.splice(0, this.observablePeripheralArray.length);
            this.bluetooth.startScanning(
              {
                filters: [{serviceUUID:'180d'}],   // pass an empty array to scan for all services
                seconds: 4,         // passing in seconds makes the plugin stop scanning after <seconds> seconds
                onDiscovered: function (peripheral) {
                  this.observablePeripheralArray.push(fromObject(peripheral));
                }
              }
            ).then(function() {
              this.isLoading = false;
            },
            function (err) {
                this.isLoading = false;
              alert({
                title: "Whoops!",
                message: err,
                okButtonText: "OK, got it"
              });
            });
          };
    }

我收到这个错误:

JS: Unhandled Promise rejection: Permission denied ; Zone: <root> ; Task: null ; Value: Permission denied undefined

蓝牙已启用并且已从 Phone

授予权限

这是一个权限错误。将此粘贴到您的 android manifest.xml

<uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>