0

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

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",
        }
      );
          

我使用以下选项开始扫描:-

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();

我的扫描结果为空。我将扫描间隔保持为 60000 毫秒和 40000 毫秒超时停止,但当应用程序在前台运行时立即扫描结果很好。

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

4

0 回答 0