我正在使用以下代码初始化蓝牙和外围设备:-
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中也添加了对前台服务的许可