BLE藍牙 onCharacteristicChanged()不回調問題

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);

 

 


 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章