在尝试读取Android API 18中的蓝牙低能量Gatt特征的值,我遇到了以下困境:检索存储在特征中的值的正确方法是什么?在此动作发生的情况下,堆栈的级别?

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

  • bluetoothgatt .readcharacters(bluetoothgatt Characteristic特征)
  • bluetoothgatt characterativers .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)
.

此函数正在使用蓝牙的特征值更新您的蓝牙曲线特征对象(在您的Android设备上)。

BluetoothGattCharacteristic.getValue()
.

此函数只是BluetoothGatt Characteristic对象的一个getter函数。Android和蓝牙设备之间没有任何事务。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top