做个小笔记,具体有关Android 蓝牙Ble的问题请看下面两篇文章,写的很实用
最近在做一个智能硬件的项目,遇到一个问题浪费了我三天时间,所以决定把它记录下来。我访问各大论坛没有一个明确的答案,所以我只能错误和尝试,终于是把这个问题解决了。
具体解决步骤:
检测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”“
临时做个笔记,等忙完这段时间再好好总结一下遇到的其他问题,希望这点文字能帮助一部分人。