0

I am trying to write data by using the blow code, successfully received on the target.

boolean status = mBluetoothGatt.writeCharacteristic(characteristic);

byte[] value = new byte[1];
            value[0] = (byte)inputvalue;
            characteristic.setValue(value);

            if (value.length <20){
                boolean status = mBluetoothGatt.writeCharacteristic(characteristic);
                Log.d("send Status ******-  : ", String.valueOf(status));
            }

But, When I am trying the write the multiple times can't send the data. Also tried to send with a 2 second delay then, it is working fine. How can I do it with out a delay

Vineesh TP
  • 7,755
  • 12
  • 66
  • 130

1 Answers1

3

BLE on Android is asynchronous and notoriously difficult to work with. Typically you have to wait for the first GATT operation to complete before you can perform follow up GATT operation (which is why it works when you add a delay).

I would recommend you checkout this project from Nordic semiconductor which includes a nice queue processor that makes BLE manageable. https://github.com/NordicSemiconductor/puck-central-android

ayvazj
  • 3,943
  • 1
  • 14
  • 14