wx.offBLECharacteristicValueChange()
// 移除连接状态监听
wx.offBLEConnectionStateChange();
// 移除设备发现监听
wx.offBluetoothDeviceFound();
// await this.closeBLEConnection()
await this.closeConnectionWithRetry(yourDeviceId).then(() => {
console.log('处理完成');
}).catch(err => {
console.error('最终关闭失败', err);
});
await this.closeConnectionWithRetry(this.mac);
// 设备连接状态 - 小程序端
wx.getConnectedBluetoothDevices({
success: (res) => {
if (res.devices.length > 0) {
console.log("仍有设备连接:", res.devices);
// 尝试逐个关闭
res.devices.forEach(device => {
wx.closeBLEConnection({ deviceId: device.deviceId });
});
} else {
console.log("无设备连接,但系统状态仍显示连接 → 鸿蒙系统 UI 未刷新");
}
}
});
// 最终方案 1. 先关闭蓝牙适配器
wx.closeBluetoothAdapter({
success: () => {
console.log("尝试关闭蓝牙适配器");
// 2. 延迟 2 秒后重新打开
setTimeout(() => {
wx.openBluetoothAdapter({
success: () => {
console.log("重新打开蓝牙适配器,强制刷新状态");
},
fail: (err) => {
console.error("重新打开蓝牙失败:", err);
}
});
}, 2000);
},
fail: (err) => {
console.error("关闭蓝牙适配器失败:", err);
}
});
async closeConnectionWithRetry(deviceId, retryCount = 3) {
console.log('closeConnectionWithRetry关闭',deviceId, retryCount);
return new Promise((resolve, reject) => {
wx.closeBLEConnection({
deviceId,
success: (res) => {
console.log('蓝牙连接已关闭',deviceId);
// 关键:等待2秒让系统底层处理
setTimeout(() => {
// 可选:再次检查系统状态是否同步
wx.getBluetoothAdapterState({
success: (stateRes) => {
console.log('当前蓝牙适配器状态(小程序获取):', stateRes.discovering ? '开启' : '关闭');
// 即使这里显示关闭,系统状态栏可能还是延迟的
}
});
resolve(res);
}, 2000); // 延迟2000毫秒
},
fail: (err) => {
console.error(`关闭失败(${retryCount}次剩余):`, err.errMsg);
if (retryCount > 0) {
setTimeout(() => {
this.closeConnectionWithRetry(deviceId, retryCount - 1);
}, 1000); // 1秒后重试
}
if (retryCount > 0) {
setTimeout(() => this.closeConnectionWithRetry(deviceId, retryCount - 1), 1000);
} else {
reject(err);
}
}
});
});
}
提示处理成功,无设备连接,蓝牙状态已关闭,关闭蓝牙适配器正常,重启蓝牙适配器也正常
但是蓝牙状态依旧是连接中
日志如下:

请具体描述问题出现的流程,并提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。
https://developers.weixin.qq.com/s/6ISp1fmP8b3l