测试设备:android 4.4
Connection工作正常,但我的回调函数的onDescriptorWrite方法永远不会被调用。并且获得了bluetoothGatt和特性。但是当我想设置-CharacteristicNotification和writeDescriptor时,没有收到回调,包括onDescriptorWrite和onCharacteristicChanged。通知代码如下所示:
private static void enableMagnetometerNotifications(BluetoothGatt bluetoothGatt) {
UUID magnetServiceUuid = UUID.fromString("f000aa30-0451-4000-b000-000000000000");
UUID magnetDataUuid = UUID.fromString("f000aa31-0451-4000-b000-000000000000");
UUID CCC = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb");
boolean ok = false;
boolean notify = false;
BluetoothGattService magnetService = bluetoothGatt.getService(magnetServiceUuid);
BluetoothGattCharacteristic magnetDataCharacteristic = magnetService.getCharacteristic(
magnetDataUuid);
notify = bluetoothGatt.setCharacteristicNotification(
magnetDataCharacteristic, true); //Enabled locally
if (notify){
BluetoothGattDescriptor config = magnetDataCharacteristic.getDescriptor(CCC);
List<BluetoothGattDescriptor> cof = magnetDataCharacteristic.getDescriptors();
for(BluetoothGattDescriptor a: cof ){
Log.i("GattDescriptor ",a.getUuid().toString());
}
ok = config.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
if(ok){
mBusy = true;
bluetoothGatt.writeDescriptor(config); //Enabled remotely
//delay 300 seconds
waitIdle(300);
}
}