【笔记】蓝牙BLE开发记录

一直没有养成随时记录的习惯,这里记录一些蓝牙BLE开发使用中遇到的问题。

BluetoothGatt status 133

这个错误状态发生在连接时,每次连接数超上限的时候就会出现,一般在使用中用bluetoothGatt.close()释放当前Gatt连接资源。

打开通知时回调onDescriptorWrite returns status 128

开发中需要根据设备的属性值bluetoothGattCharacteristic.getProperties()是判断是支持通知(ENABLE_NOTIFICATION_VALUE)还是支持指示(ENABLE_INDICATION_VALUE)来设置描述符

    private BluetoothGatt mBluetoothGatt;
    BluetoothGattCharacteristic characteristic;
    boolean enabled;
    ...
    mBluetoothGatt.setCharacteristicNotification(characteristic, enabled);
    ...
    BluetoothGattDescriptor descriptor = characteristic.getDescriptor(
            UUID.fromString(SampleGattAttributes.CLIENT_CHARACTERISTIC_CONFIG));
    //根据特征属性设置
    if((characteristic.getProperties()&BluetoothGattCharacteristic.PROPERTY_NOTIFY)==0) {
        //支持指示
        descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);
    }else{
        //支持通知
        descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
    }
    mBluetoothGatt.writeDescriptor(descriptor);

获取服务后,获取特征值列表为空

找不到解决方法,重新扫描连接获取服务再去获取特征值就又有了




  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值