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

在尝试阅读 Android API 18中蓝牙低功耗GATT特性的价值时,我遇到了以下困境:检索存储在特性中的值的正确方法是什么?并且堆栈的哪个级别应该发生这种行为?

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

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

public void onClick(View v){        
    byteValue = mBTValueCharacteristic.getValue();
    if ((byteValue[0] & 0x01) == 1)
        byteValue[0] = 0x00;
    else
        byteValue[0] = 0x01;

    mBTValueCharacteristic.setValue(byteValue);
    mBTGatt.writeCharacteristic(mBTValueCharacteristic);
}

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

解决方法

BluetoothGatt.readCharacteristic(BluetoothGattCharacteristic characteristic)

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

BluetoothGattCharacteristic.getValue()

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

相关文章

这篇“android轻量级无侵入式管理数据库自动升级组件怎么实现...
今天小编给大家分享一下Android实现自定义圆形进度条的常用方...
这篇文章主要讲解了“Android如何解决字符对齐问题”,文中的...
这篇文章主要介绍“Android岛屿数量算法怎么使用”的相关知识...
本篇内容主要讲解“Android如何开发MQTT协议的模型及通信”,...
本文小编为大家详细介绍“Android数据压缩的方法是什么”,内...