0
APP에서 일부 Bluetooth 특성을 읽으려고합니다. 이제 Gatt Server에서 특성이 변경된 후에 수행 할 작업에 문제가 있습니다. 처음에 나는이 같은 또 다시 특성에 대한 읽기를 다시 트리거하기 위해 스레드를 사용하려고했습니다Android BLE 읽기 Gatt 특성
new Thread(new Runnable() {
@Override
public void run() {
int[] newData = new int[30];
while(true){
try{
for(int i=0;i<newData.length;i++){
newData[i] = 0;
}
BluetoothGatt tmpGatt = refExtDataClass.getRefBluetoothGatt();
tmpGatt.readCharacteristic(characteristic);
byte[] value = characteristic.getValue();
for(int i=0;i<newData.length;i++){
newData[i] = value[i];
}
refExtDataClass.setNmData(newData);
}catch(Exception e){
break;
}
}
}
}).start();
그러나 문제는 내가 것 같은 데이터를 (한 지점에서 손상 것처럼 것 같다이다 항상 동일한 데이터를 MCU 측에서 특성에 기록).
이와 같은 BLE 데이터를 읽을 수 있습니까? 항상 BLE 데이터를 읽을 수있는 방법이 있습니까? 아니면 내 애플 리케이션 측면에서 그것을 업데이 트합니까?
추가 코드가 필요하면 알려주십시오.
나는 "솔루션"이 전혀 마음에 들지 않는 또 다른 방법이 있다는 말을 듣기 좋습니다. 나는 그저 내가 gatt 클라이언트 측에서 알림을 "활성화"해야한다는 것을 읽었습니다. 만약 내가 characteristic.addDescriptor (BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE)를 사용하고 있다면 충분합니까? –
아니요는 https://developer.android.com/guide/topics/connectivity/bluetooth-le.html#notification에서 예제를 참조하십시오. – Emil