【发布时间】:2013-11-29 14:43:26
【问题描述】:
在尝试读取 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); }
以上是导致我遇到此问题的原始代码。在其中,我尝试读取特征的值,然后使用按钮简单地切换其状态。
【问题讨论】:
标签: bluetooth-lowenergy android-bluetooth android-4.3-jelly-bean