当应用程序是Cordova应用程序中的背景时,蓝牙背景扫描不起作用

时间:2020-07-14 17:52:19

标签: android cordova cordova-plugins background-service bluetoothlescanner

我正在使用以下代码初始化蓝牙和外围设备:-

bluetoothle.initialize(function initializeResult(result) {
        console.log(result);
      },  {
        request: true,
        statusReceiver: true,
        restoreKey: "bluetoothleplugin",
      });
     bluetoothle.initializePeripheral(
        function initializeResult(result) {
          console.log("initialize peripheral");
          console.log(result);
        },
        function error(result) {
          console.log("init peripheral error");
          console.log(result);
        },
        {
          request: true,
          restoreKey: "bluetoothleplugin",
        }
      );
          

然后我使用foll选项开始扫描:-

bluetoothle.startScan(
        (result: BluetoothScanResult) => {
          console.log("result in searching");
          // console.log(result);
          if (result.name) {
            bluetoothresult.push(result);
            resulllt.push(result);
            bluetoothresultconst.push(result);
            resullltconst.push(result);
          }
        },
        function startScanErrorCallback(err) {
          console.log("printing err");
          console.log(err);
        },
        { serviceUuids: [],allowDuplicates:true }
      );

      setTimeout(() => {
        bluetoothle.stopScan(
          (result) => {
            console.log("stopping the scanning");
            console.log(bluetoothresult);
            if (bluetoothresult.length != 0) {
              console.log("got result length is more than zero");
                }
          },
          function stopScanErrorCallback(result) {
            console.log("came error in stopping the scanning ");
            console.log(result);
          }
        );
      }, 40000);

我的扫描结果很好,但是当我使用以下代码将应用程序移至后台时:- cordova.plugins.backgroundMode.moveToBackground();

我的扫描结果为空。我将扫描间隔保持为60000ms和40000ms停止超时 但是当应用程序在前景扫描中运行时,结果很好。

注意:-我正在Android 9设备中检查应用程序,甚至在cordova的manifest.xml和plugin.xml中也添加了对前台服务的许可

0 个答案:

没有答案
相关问题