Pergunta

Ao tentar ler o valor de uma característica Bluetooth Low-Energy GATT na API Android 18, me deparei com o seguinte dilema:Qual é a maneira correta de recuperar o valor armazenado em uma característica?E em que nível da pilha esta ação deve ocorrer?

Ao conduzir minha própria pesquisa, me deparei com o que entendo serem dois métodos possíveis:

  • BluetoothGatt.readCharacteristic (característica BluetoothGattCharacteristic)
  • BluetoothGattCaracterística.Obter valor()

    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);
    }
    

Acima está o código original que me levou a esse problema.Nele, tento ler o valor de uma característica e simplesmente alternar seu estado usando um botão.

Foi útil?

Solução

BluetoothGatt.readCharacteristic(BluetoothGattCharacteristic characteristic)

Esta função está atualizando seu objeto BluetoothGattCharacteristic (em seu dispositivo Android) usando o valor característico do Bluetooth .

BluetoothGattCharacteristic.getValue()

Esta função é apenas uma função getter do objeto BluetoothGattCharacteristic.Não há nenhuma transação entre o Android e o dispositivo bluetooth.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top