一直没有养成随时记录的习惯,这里记录一些蓝牙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);
获取服务后,获取特征值列表为空
找不到解决方法,重新扫描连接获取服务再去获取特征值就又有了