@Override public void run() throws Exception { descriptor.setValue(data); } });
// 0x2902 org.bluetooth.descriptor.gatt.client_characteristic_configuration.xml UUID uuid = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb"); BluetoothGattDescriptor descriptor = characteristic.getDescriptor(uuid); descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); gatt.writeDescriptor(descriptor);
/** * Adds a {@link BluetoothGattDescriptor} with specified parameters. * * @param uuid descriptor UUID * @param data locally stored value of the descriptor */ public DescriptorsBuilder addDescriptor(@NonNull UUID uuid, @NonNull byte[] data) { BluetoothGattDescriptor bluetoothGattDescriptor = new BluetoothGattDescriptor(uuid, 0); bluetoothGattDescriptor.setValue(data); bluetoothGattDescriptors.add(bluetoothGattDescriptor); return this; }
protected static final UUID CHARACTERISTIC_UPDATE_NOTIFICATION_DESCRIPTOR_UUID = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb"); public boolean setCharacteristicNotification(BluetoothDevice device, UUID serviceUuid, UUID characteristicUuid, boolean enable) { if (IS_DEBUG) Log.d(TAG, "setCharacteristicNotification(device=" + device.getName() + device.getAddress() + ", UUID=" + characteristicUuid + ", enable=" + enable + " )"); BluetoothGatt gatt = mGattInstances.get(device.getAddress()); //I just hold the gatt instances I got from connect in this HashMap BluetoothGattCharacteristic characteristic = gatt.getService(serviceUuid).getCharacteristic(characteristicUuid); gatt.setCharacteristicNotification(characteristic, enable); BluetoothGattDescriptor descriptor = characteristic.getDescriptor(CHARACTERISTIC_UPDATE_NOTIFICATION_DESCRIPTOR_UUID); descriptor.setValue(enable ? BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE : new byte[] { 0x00, 0x00 }); return gatt.writeDescriptor(descriptor); //descriptor write operation successfully started? }
@Override protected boolean startOperation(BluetoothGatt bluetoothGatt) { bluetoothGattDescriptor.setValue(data); /* * According to the source code below Android 7.0.0 the BluetoothGatt.writeDescriptor() function used * writeType of the parent BluetoothCharacteristic which caused operation failure (for instance when * setting Client Characteristic Config). With WRITE_TYPE_DEFAULT problem did not occurred. * Compare: * https://android.googlesource.com/platform/frameworks/base/+/android-6.0.1_r74/core/java/android/bluetooth/BluetoothGatt.java#1039 * https://android.googlesource.com/platform/frameworks/base/+/android-7.0.0_r1/core/java/android/bluetooth/BluetoothGatt.java#947 */ final BluetoothGattCharacteristic bluetoothGattCharacteristic = bluetoothGattDescriptor.getCharacteristic(); final int originalWriteType = bluetoothGattCharacteristic.getWriteType(); bluetoothGattCharacteristic.setWriteType(bluetoothGattCharacteristicDefaultWriteType); final boolean success = bluetoothGatt.writeDescriptor(bluetoothGattDescriptor); bluetoothGattCharacteristic.setWriteType(originalWriteType); return success; } }
BluetoothGattDescriptor clientConfig = characteristic.getDescriptor(CCC); clientConfig.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); // or //clientConfig.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE); mBluetoothGatt.writeDescriptor(clientConfig);
public void setCharacteristicNotification(BluetoothGattCharacteristic characteristic, boolean enabled) { if (mBluetoothAdapter == null || mBluetoothGatt == null) { Log.w(TAG, "BluetoothAdapter not initialized"); return; } mBluetoothGatt.setCharacteristicNotification(characteristic, enabled); BluetoothGattDescriptor descriptor = characteristic.getDescriptor( UUID.fromString("00002902-0000-1000-8000-00805f9b34fb")); descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); mBluetoothGatt.writeDescriptor(descriptor); }
@Override public void execute() { if (mBluetoothGatt == null || value == null || mBluetoothGattDescriptor == null) { Log.e(TAG, "Error: " + TAG + ".execute, object = null"); } else { mBluetoothGattDescriptor.setValue(value); if (!mBluetoothGatt.writeDescriptor(mBluetoothGattDescriptor)) { Log.e(TAG, "Error: " + TAG + " was not executed correctly: " + mBluetoothGattDescriptor.getUuid().toString()); } } }
@Override public void onServicesDiscovered(BluetoothGatt gatt, int status) { if (status == BluetoothGatt.GATT_SUCCESS) { BluetoothGattService gattService = gatt.getService(UUID.fromString(C5_OPENXC_BLE_SERVICE_UUID)); BluetoothGattCharacteristic gattCharacteristic = gattService.getCharacteristic(UUID.fromString(C5_OPENXC_BLE_CHARACTERISTIC_NOTIFY_UUID)); gatt.setCharacteristicNotification(gattCharacteristic, true); BluetoothGattDescriptor descriptor = gattCharacteristic.getDescriptor(UUID.fromString(C5_OPENXC_BLE_DESCRIPTOR_NOTIFY_UUID)); descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); gatt.writeDescriptor(descriptor); } }
/** Will cancel an in-progress connection, and close the socket */ public void cancel() { gat.setCharacteristicNotification(cc,false); descriptor.setValue( BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE); gat.writeDescriptor(descriptor); gat.disconnect(); gat.close(); Log.i("H7ConnectThread", "Closing HRsensor"); }
public void setCharacteristicNotification(BluetoothGattCharacteristic characteristic, boolean enabled) { Log.i(TAG, "Characteristic setting notification"); if (mBluetoothGatt != null) { mBluetoothGatt.setCharacteristicNotification(characteristic, enabled); BluetoothGattDescriptor descriptor = characteristic.getDescriptor(UUID.fromString(HM10Attributes.CLIENT_CHARACTERISTIC_CONFIG)); Log.i(TAG, "Descriptor found: " + descriptor.getUuid()); descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); mBluetoothGatt.writeDescriptor(descriptor); } }
public void setCharacteristicNotification(BluetoothGattCharacteristic characteristic, boolean enabled) { Log.i(TAG, "Characteristic setting notification"); if (mBluetoothGatt != null) { mBluetoothGatt.setCharacteristicNotification(characteristic, enabled); BluetoothGattDescriptor descriptor = characteristic.getDescriptor(UUID.fromString(HM10Attributes.CLIENT_CHARACTERISTIC_CONFIG)); Log.i(TAG, "Descriptor found: " + descriptor.getUuid()); descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); mBluetoothGatt.writeDescriptor(descriptor); } }
public void setCharacteristicIndication(BluetoothGattCharacteristic characteristic, boolean enabled) { Log.i(TAG, "Characteristic setting indication"); if (mBluetoothGatt != null) { mBluetoothGatt.setCharacteristicNotification(characteristic, enabled); BluetoothGattDescriptor descriptor = characteristic.getDescriptor(UUID.fromString(HM10Attributes.CLIENT_CHARACTERISTIC_CONFIG)); Log.i(TAG, "Descriptor found: " + descriptor.getUuid()); descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE); mBluetoothGatt.writeDescriptor(descriptor); } }
public void setCharacteristicIndication(BluetoothGattCharacteristic characteristic, boolean enabled) { Log.i(TAG, "Characteristic setting indication"); if (mBluetoothGatt != null) { mBluetoothGatt.setCharacteristicNotification(characteristic, enabled); BluetoothGattDescriptor descriptor = characteristic.getDescriptor(UUID.fromString(HM10Attributes.CLIENT_CHARACTERISTIC_CONFIG)); Log.i(TAG, "Descriptor found: " + descriptor.getUuid()); descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE); mBluetoothGatt.writeDescriptor(descriptor); } }
public void setCharacteristicNotification(BluetoothGattCharacteristic characteristic, boolean enabled) { Log.i(TAG, "Characteristic setting notification"); if (mBluetoothGatt != null) { mBluetoothGatt.setCharacteristicNotification(characteristic, enabled); BluetoothGattDescriptor descriptor = characteristic.getDescriptor(UUID.fromString(HM10Attributes.CLIENT_CHARACTERISTIC_CONFIG)); Log.i(TAG, "Descriptor found: " + descriptor.getUuid()); descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); mBluetoothGatt.writeDescriptor(descriptor); } }
public void setCharacteristicIndication(BluetoothGattCharacteristic characteristic, boolean enabled) { Log.i(TAG, "Characteristic setting indication"); if (mBluetoothGatt != null) { mBluetoothGatt.setCharacteristicNotification(characteristic, enabled); BluetoothGattDescriptor descriptor = characteristic.getDescriptor(UUID.fromString(HM10Attributes.CLIENT_CHARACTERISTIC_CONFIG)); Log.i(TAG, "Descriptor found: " + descriptor.getUuid()); descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE); mBluetoothGatt.writeDescriptor(descriptor); } }
public void setCharacteristicNotification(BluetoothGattCharacteristic characteristic, boolean enabled) { Log.i(TAG, "Characteristic setting notification"); mBluetoothGatt.setCharacteristicNotification(characteristic, enabled); Log.i(TAG, "UUID FOUND: " + characteristic.getUuid()); BluetoothGattDescriptor descriptor = characteristic.getDescriptor(UUID.fromString(HM10Attributes.CLIENT_CHARACTERISTIC_CONFIG)); Log.i(TAG, "Descriptor found: " + descriptor.getUuid()); descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); mBluetoothGatt.writeDescriptor(descriptor); }
public void setCharacteristicIndication(BluetoothGattCharacteristic characteristic, boolean enabled) { Log.i(TAG, "Characteristic setting notification"); mBluetoothGatt.setCharacteristicNotification(characteristic, enabled); Log.i(TAG, "UUID FOUND: " + characteristic.getUuid()); BluetoothGattDescriptor descriptor = characteristic.getDescriptor(UUID.fromString(HM10Attributes.CLIENT_CHARACTERISTIC_CONFIG)); Log.i(TAG, "Descriptor found: " + descriptor.getUuid()); descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE); mBluetoothGatt.writeDescriptor(descriptor); }
public void setCharacteristicIndication(BluetoothGattCharacteristic characteristic, boolean enabled) { Log.i(TAG, "Characteristic setting notification"); mBluetoothGatt.setCharacteristicNotification(characteristic, enabled); Log.i(TAG, "UUID FOUND: " + characteristic.getUuid()); BluetoothGattDescriptor descriptor = characteristic.getDescriptor(UUID.fromString(HM10Attributes.CLIENT_CHARACTERISTIC_CONFIG)); Log.i(TAG, "Descriptor found: " + descriptor.getUuid()); descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE); mBluetoothGatt.writeDescriptor(descriptor); }
public void setCharacteristicNotification(BluetoothGattCharacteristic characteristic, boolean enabled) { Log.i(TAG, "Characteristic setting notification"); mBluetoothGatt.setCharacteristicNotification(characteristic, enabled); Log.i(TAG, "UUID FOUND: " + characteristic.getUuid()); BluetoothGattDescriptor descriptor = characteristic.getDescriptor(UUID.fromString(HM10Attributes.CLIENT_CHARACTERISTIC_CONFIG)); Log.i(TAG, "Descriptor found: " + descriptor.getUuid()); descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); mBluetoothGatt.writeDescriptor(descriptor); }