est*_*bro 10 bluetooth-lowenergy android-bluetooth android-4.3-jelly-bean
在试图读取Android API 18中蓝牙低功耗GATT特性的值时,我遇到了以下困境:检索存储在特征中的值的正确方法是什么?并且应该在哪个级别的堆栈中执行此操作?
在进行自己的研究时,我偶然发现了两种可能的方法:
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);
}
Run Code Online (Sandbox Code Playgroud)以上是引导我解决这个问题的原始代码.在其中,我尝试读取特征的值,并使用按钮简单地切换其状态.
BluetoothGatt.readCharacteristic(BluetoothGattCharacteristic characteristic)
Run Code Online (Sandbox Code Playgroud)
此功能使用蓝牙的特征值更新您的BluetoothGattCharacteristic对象(在您的Android设备上).
BluetoothGattCharacteristic.getValue()
Run Code Online (Sandbox Code Playgroud)
此功能只是BluetoothGattCharacteristic对象的getter功能.android和蓝牙设备之间没有任何交易.
| 归档时间: |
|
| 查看次数: |
9065 次 |
| 最近记录: |