I need to send message to custom device via BLE.
I am able to send message below 20 bytes. I used just:
public boolean writeCharacteristic(byte[] value){
if (mBluetoothGatt == null) {
Log.e(TAG, "lost connection");
return false;
}
BluetoothGattService Service = mBluetoothGatt.getService(UUID_SERVICE_GENERIC_ATTRIBUTE);
if (Service == null) {
Log.e(TAG, "service not found!");
return false;
}
BluetoothGattCharacteristic charac = Service.getCharacteristic(UUID_WRITE);
if (charac == null) {
Log.e(TAG, "char not found!");
return false;
}
charac.setValue(value);
boolean status = mBluetoothGatt.writeCharacteristic(charac);
return status;
}
But I need to send longer message in "as short time as possible". I found: Android: Sending data >20 bytes by BLE
but I need to use synchronized method and onCharacteristicWrite (this should be the fastest way).
I found: http://blog.stylingandroid.com/bluetooth-le-part-6/, but not everything is clear for me.
Do you have some easy example how to send message via ble using synchronized methods?