Reputation: 114
I am hosting a GATT server in the Nexus 9 (as a peripheral). I am able to implement a characteristic with Read property and Notify property separately. How to host a characteristics with Read and Notify property?
In the below code Read property is implemented:
final String SERVICE_A = "0000fff0-0000-1000-8000-00805f9b34fb";
final String CHAR_READ1 = "0000fff1-0000-1000-8000-00805f9b34fb";
BluetoothGattService previousService =
mGattServer.getService( UUID.fromString(SERVICE_A));
if(null != previousService)
mGattServer.removeService(previousService);
BluetoothGattCharacteristic read1Characteristic = new BluetoothGattCharacteristic(
UUID.fromString(CHAR_READ1),
BluetoothGattCharacteristic.PROPERTY_READ,
BluetoothGattCharacteristic.PERMISSION_READ
);
read1Characteristic.setValue(read1Data.getBytes());
BluetoothGattService AService = new BluetoothGattService(
UUID.fromString(SERVICE_A),
BluetoothGattService.SERVICE_TYPE_PRIMARY);
AService.addCharacteristic(read1Characteristic);
full source code here
Upvotes: 1
Views: 3370
Reputation: 427
Those properties are bitwise, so you can do the following:
BluetoothGattCharacteristic read1Characteristic = new BluetoothGattCharacteristic(
UUID.fromString(CHAR_READ1),
BluetoothGattCharacteristic.PROPERTY_READ | BluetoothGattCharacteristic.PROPERTY_NOTIFY,
BluetoothGattCharacteristic.PERMISSION_READ
);
Upvotes: 2