Android低功耗藍牙開發,onCharacteristicChanged()怎麼也不回調,原因查找:
1、查看藍牙服務特徵的Properties是否爲 PROPERTY_NOTIFY
int properties = characteristic.getProperties();//16
2、BluetoothGattDescriptor寫入是否正確
BluetoothGattDescriptor descriptor =
characteristic.getDescriptor(UUID
.fromString
("00002902-0000-1000-8000-00805f9b34fb"));
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
mBluetoothGatt.writeDescriptor(descriptor);
3、訂閱通知是否設置成功
//訂閱通知
boolean notification = mBluetoothGatt.setCharacteristicNotification(characteristic, true);//是否爲true
4、如果以上均沒有問題,就要確認數據的字節數,默認爲20個字節,如果字節數過大需要設置接收字節
mBluetoothGatt.requestMtu(int len);