Created
April 2, 2013 19:13
-
-
Save lnanek/5295269 to your computer and use it in GitHub Desktop.
Using notifications with the HTC BLE SDK
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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