Android 蓝牙BLE 中onCharacteristicChanged不走回调的解决方案

做个小笔记,具体有关Android 蓝牙Ble的问题请看下面两篇文章,写的很实用

  1. Android BLE开发——Android手机与BLE终端通信初识
  2. Android 蓝牙开发(二)Ble 开发(android4.3)

最近在做一个智能硬件的项目,遇到一个问题浪费了我三天时间,所以决定把它记录下来。我访问各大论坛没有一个明确的答案,所以我只能错误和尝试,终于是把这个问题解决了。

具体解决步骤:


检测setCharacteristicNotification(BluetoothGattCharacteristic characteristic,boolean enabled)方法是否书写正确

public void setCharacteristicNotification(BluetoothGattCharacteristic characteristic,
                                              boolean enabled) {
        if (mBluetoothAdapter == null || mBluetoothGatt == null) {
            Logger.e("BluetoothAdapter not initialized");
            return;
        }
        boolean notification = mBluetoothGatt.setCharacteristicNotification(characteristic, enabled);
        Logger.e("ble notification  ="+notification);
 //这里可以加入判断对指定的UUID值进行订阅
        BluetoothGattDescriptor descriptor = characteristic.getDescriptor(BluetoothUUID.CLIENT_CHARACTERISTIC_CONFIG);
        descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
        mBluetoothGatt.writeDescriptor(descriptor);
        Logger.e("ble 订阅");       
    }

通过反编译和用其他的软件进行调试我发现了CLIENT_CHARACTERISTIC_CONFIG是个固定值“00002902-0000-1000-8000-00805f9b34fb”


      临时做个笔记,等忙完这段时间再好好总结一下遇到的其他问题,希望这点文字能帮助一部分人。
  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 7
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值