1
我在Nexus 9(作爲外設)託管GATT服務器。我能夠分別實現具有讀取屬性和通知屬性的特性。如何使用Read和Notify屬性託管特徵?如何將READ,NOTIFY屬性添加到Android BLE GATT Server中的自定義特徵?
在下面的代碼讀取屬性實現:
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