我在 Nexus 9 中托管了一个 GATT 服务器(作为外围设备)。我能够分别使用 Read 属性和 Notify 属性实现一个特性。如何承载具有读取和通知属性的特征?
在下面的代码中实现了读取属性:
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);
完整源代码 here
最佳答案
这些属性是按位的,因此您可以执行以下操作:
BluetoothGattCharacteristic read1Characteristic = new BluetoothGattCharacteristic(
UUID.fromString(CHAR_READ1),
BluetoothGattCharacteristic.PROPERTY_READ | BluetoothGattCharacteristic.PROPERTY_NOTIFY,
BluetoothGattCharacteristic.PERMISSION_READ
);
关于android - 如何将 READ、NOTIFY 属性添加到 Android BLE GATT 服务器中的自定义特性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34158339/