蓝牙低能量 – 在Android中阅读GATT特性的正确方法是什么?

前端之家收集整理的这篇文章主要介绍了蓝牙低能量 – 在Android中阅读GATT特性的正确方法是什么?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在尝试阅读 Android API 18中蓝牙低功耗GATT特性的价值时,我遇到了以下困境:检索存储在特性中的值的正确方法是什么?并且堆栈的哪个级别应该发生这种行为?

在进行自己的研究时,我偶然发现我所理解的是两种可能的方法

> BluetoothGatt.readCharacteristic(BluetoothGattCharacteristic特性)
> BluetoothGattCharacteristic.getValue()

  1. public void onClick(View v){
  2. byteValue = mBTValueCharacteristic.getValue();
  3. if ((byteValue[0] & 0x01) == 1)
  4. byteValue[0] = 0x00;
  5. else
  6. byteValue[0] = 0x01;
  7.  
  8. mBTValueCharacteristic.setValue(byteValue);
  9. mBTGatt.writeCharacteristic(mBTValueCharacteristic);
  10. }

以上是导致我这个问题的原始代码.在其中,我尝试读取一个特征的值,只需使用按钮切换其状态.

解决方法

  1. BluetoothGatt.readCharacteristic(BluetoothGattCharacteristic characteristic)

功能使用蓝牙的特征值更新您的BluetoothGattCharacteristic对象(在Android设备上).

  1. BluetoothGattCharacteristic.getValue()

功能只是BluetoothGattCharacteristic对象的getter函数. Android和蓝牙设备之间没有任何交易.

猜你在找的Android相关文章