문제

Android API 18에서 블루투스 저에너지 GATT 특성의 값을 읽으려는 경우 다음 딜레마를 가로 질러 나타났습니다. 특성에 저장된 값을 검색하는 적절한 방법은 무엇입니까?그리고 어떤 수준의 스택의 수준 에서이 작업이 수행되어야합니까?

내 자신의 연구를 수행 할 때, 나는 내가 이해하는 것에 대해 무의식적으로 두 가지 가능한 방법이다 :

  • bluetoothgatt .ReadCharacteristic (BluetoothGatcharacteristic 특성)
  • 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)
.

이 함수는 Bluetooth에서 특성 값을 사용하여 BluetoothGattCharacteristic 객체를 업데이트합니다.

BluetoothGattCharacteristic.getValue()
.

이 함수는 BluetoothGattCharacteristic 객체의 getter 함수 일뿐입니다.Android와 Bluetooth 장치간에 트랜잭션은 없습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top