You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
iOS → Android messages over 157 characters are not received; Android → iOS works up to 352 bytes #90
Send a message with more than 157 characters to an Android device.
Observe that nothing is received on Android.
On iOS, the message appears to be sent successfully.
Expected behavior
Android should receive the full message from iOS, regardless of length (within BLE limits). If chunking is required, either iOS should handle fragmentation, or Android should support reassembly.
Actual behavior
When sending a message from iOS to Android that exceeds 157 characters, the Android app does not receive the message at all. It silently fails or is possibly discarded.
Meanwhile, Android can send messages up to 352 bytes to iOS without any issue.
Working cases:
✅ Android → iOS: up to 352 bytes = works fine
✅ iOS → Android: up to 157 characters = works fine
Broken case:
❌ iOS → Android: over 157 characters = not received at all
I’ve debugged the Android side further and noticed the following:
onCharacteristicWriteRequest() is correctly triggered.
The preparedWrite flag is true — which indicates that a Reliable Write (long write) transaction is in progress.
However, only the chunk with offset = 0 is being processed.
Subsequent chunks (with non-zero offsets) are being ignored, so the full message is never assembled.
This is likely the root cause of the issue when iOS sends a message longer than the MTU size (512+ chars in this case).
👉 Suggestion: Android should store all incoming chunks (when preparedWrite == true) and finalize the write in onExecuteWrite() to properly support long writes.
Let me know if you'd like help testing a potential fix!
**Example Code: **
// Temporary buffer to store incoming chunks per deviceval writeBuffer = mutableMapOf<BluetoothDevice, MutableList<Pair<Int, ByteArray>>>()
val gattServerCallback =object:BluetoothGattServerCallback() {
overridefunonCharacteristicWriteRequest(
device:BluetoothDevice,
requestId:Int,
characteristic:BluetoothGattCharacteristic,
preparedWrite:Boolean,
responseNeeded:Boolean,
offset:Int,
value:ByteArray
) {
if (preparedWrite) {
// Buffer the chunk with its offsetval buffer = writeBuffer.getOrPut(device) { mutableListOf() }
buffer.add(offset to value)
} else {
// Handle short write directly
characteristic.value = value
}
if (responseNeeded) {
gattServer.sendResponse(device, requestId, BluetoothGatt.GATT_SUCCESS, offset, value)
}
}
overridefunonExecuteWrite(device:BluetoothDevice, execute:Boolean) {
if (execute) {
val chunks = writeBuffer[device]
if (!chunks.isNullOrEmpty()) {
// Sort by offset and mergeval completeData = chunks
.sortedBy { it.first }
.fold(ByteArray(0)) { acc, pair -> acc + pair.second }
// Now you can process the complete message// For example, assign to characteristic or parse messageLog.d("BLE", "Complete message received: ${String(completeData)}")
// Clear buffer after use
writeBuffer.remove(device)
}
} else {
// Cancel write
writeBuffer.remove(device)
}
}
}
Activity
hamzaozturk commentedon Jul 13, 2025
🔍 Additional Technical Insight:
I’ve debugged the Android side further and noticed the following:
onCharacteristicWriteRequest()is correctly triggered.preparedWriteflag istrue— which indicates that a Reliable Write (long write) transaction is in progress.offset = 0is being processed.This is likely the root cause of the issue when iOS sends a message longer than the MTU size (512+ chars in this case).
👉 Suggestion: Android should store all incoming chunks (when
preparedWrite == true) and finalize the write inonExecuteWrite()to properly support long writes.Let me know if you'd like help testing a potential fix!
**Example Code: **
Surface prepared-write rejections and reject gapped payloads