android - 如何将 READ、NOTIFY 属性添加到 Android BLE GATT 服务器中的自定义特性?

标签 android bluetooth bluetooth-lowenergy android-bluetooth

我在 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/

相关文章:

java - Cordova android 应用程序,图像覆盖在摄像机上

android - 谷歌日历 API 构建

android - 检查 Android 上 openVPN 的 VPN 连接状态

安卓 3.1 : getDefaultAdapter() returns null in android

android - Google Glass 触摸板操作对应的键盘按键是什么?

c# - Xamarin Plugin.BLE 为什么数据读取没有改变?

java - 按钮不创建文件并在按下时显示电子邮件提供商选项菜单

java - 保持 Java 蓝牙连接有效

android - 蓝牙 socket 连接

react-native - 使用 native react 杀死应用程序后,蓝牙仍然处于事件状态