You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android BLE中createBond()在部分设备上返回false的排查求助

BLE血糖仪配对问题:Motorola G32上createBond()随机返回false

我正在集成一款遵循BLE规范的血糖仪,操作流程并不复杂,但在Motorola G32手机上多次出现createBond()调用返回false的情况,这个问题触发完全随机,我排查了很久没找到头绪,想请教可能的触发原因。

createBond()是异步调用,会立即返回结果,我已经通过BroadcastReceiver监听蓝牙事件。相关代码如下:

配对触发代码

boolean tryToBond = getDevice().createBond();

if (!tryToBond) {
    if (connectCtx != null) {
        connectCtx.error(getPluginResponseObject(failedToCreateBond, "Failed to initiate pairing.  createBond() return false"));
    }

    return false;
}

蓝牙状态监听接收器代码

if (getDevice().getBondState() != BluetoothDevice.BOND_BONDED) { // 仅作说明:仅在未配对时才注册接收器并调用createBond
    pairingBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (BluetoothDevice.ACTION_BOND_STATE_CHANGED.equals(action)){
                aDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
                if (aDevice.getBondState() == BluetoothDevice.BOND_BONDED) {
                    // 设备已配对
                    Log.d("bt", "bonded");
                    pairingState = pairingStateEnum.success;
                }
                if (aDevice.getBondState() == BluetoothDevice.BOND_NONE){
                    Log.d("bt", "bonding failed");
                    pairingState = pairingStateEnum.failure;
                }
            }
        }
    };
}

可能的触发原因

  • 系统蓝牙栈资源冲突:Motorola G32的蓝牙后台可能被其他进程占用配对资源(如系统蓝牙服务、其他APP的蓝牙操作),导致调用createBond()时无法获取足够资源,随机返回false。
  • BLE设备配对状态异常:血糖仪可能存在临时蓝牙状态异常,比如连接缓存未清理、之前的配对残留未完全失效,导致手机发起配对时设备无法响应,触发createBond()失败。
  • 系统权限或后台限制:Motorola G32的Android版本可能对蓝牙配对有后台限制,比如APP处于后台时无法发起配对;或缺少BLUETOOTH_ADMIN、BLUETOOTH_CONNECT等关键权限(Android 12+需注意权限变更),导致调用失败。
  • 蓝牙适配器状态不稳定:手机蓝牙适配器可能存在临时状态波动,比如刚开启蓝牙、信号弱导致适配器内部状态异常,此时调用createBond()会直接返回false。
  • 配对请求频率过高:短时间内多次发起配对请求,系统蓝牙栈可能限流,随机拒绝部分请求,返回false。

内容的提问来源于stack exchange,提问作者tronious

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 13:20:32