简体   繁体   English

如何在Android BLE GATT Server中将READ,NOTIFY属性添加到自定义特征?

[英]How to add READ, NOTIFY property to a custom characteristic in Android BLE GATT Server?

I am hosting a GATT server in the Nexus 9 (as a peripheral). 我在Nexus 9(作为外围设备)中托管了GATT服务器。 I am able to implement a characteristic with Read property and Notify property separately. 我可以用Read属性和Notify属性分别实现一个特性。 How to host a characteristics with Read and Notify property? 如何使用“读取”和“通知”属性来承载特征?

In the below code Read property is implemented: 在下面的代码中实现了Read属性:

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 完整的源代码在这里

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
          );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM