Skip to content

Instantly share code, notes, and snippets.

@lnanek
Created April 2, 2013 19:13
Show Gist options
  • Save lnanek/5295269 to your computer and use it in GitHub Desktop.
Save lnanek/5295269 to your computer and use it in GitHub Desktop.
Using notifications with the HTC BLE SDK
@Override
public void onDeviceConnected(BluetoothDevice device) {
mService.registerForNotification(device, 0, new BleGattID("00002a37-0000-1000-8000-00805f9b34fb"));
// Note that the super class will call refresh.
super.onDeviceConnected(device);
}
@Override
public void onRefreshed(final BluetoothDevice aDevice) {
super.onRefreshed(aDevice);
final BleCharacteristic characteristic = mService.getCharacteristic(aDevice,
new BleGattID("00002a37-0000-1000-8000-00805f9b34fb"));
final byte[] value = new byte[] {
BleConstants.GATT_CLIENT_CONFIG_NOTIFICATION_BIT,
0 // CLIENT_CHAR_CONFIG_RESERVED_BYTE
};
final BleDescriptor clientConfig = characteristic.getDescriptor(
new BleGattID(BleConstants.GATT_UUID_CHAR_CLIENT_CONFIG16));
clientConfig.setValue(value);
clientConfig.setWriteType(BleConstants.GATTC_TYPE_WRITE);
mService.writeCharacteristic(aDevice, 0, characteristic);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment