问题
Device for testing:android 4.4
Connection is working fine but the onDescriptorWrite Method of my callback is never called. And the bluetoothGatt and characteristics are got. But when I want to setCharacteristicNotification and writeDescriptor, no callback is recieved, including onDescriptorWrite and onCharacteristicChanged. The notification code is showed as following:
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);
}
}
来源:https://stackoverflow.com/questions/31400114/android-sensortag-writedescriptor-failed