Im just curious if gemini is correct? Add that delay and retest it.
Sub TestData
pbReadData.Show
' 1. Request MTU
Log("Requesting MTU...")
manager.RequestMtu(64)
Sleep(500) ' Give Sony time to handshake
' 2. Set Notification
Log("Setting Notify...")
manager.SetNotify("0000fff0-0000-1000-8000-00805f9b34fb", "0000fff1-0000-1000-8000-00805f9b34fb", True)
Sleep(500) ' Wait for the CCCD descriptor write to finish
' 3. Prepare and Write Data
Dim TextToSend As String = "@" & Chr(13) & Chr(10)
Dim DataToSend() As Byte = TextToSend.GetBytes("UTF8")
Log("Writing Data: " & TextToSend)
' Wrapping in a Try block prevents the "Continue?" popup if it fails
Try
manager.WriteData("0000fff0-0000-1000-8000-00805f9b34fb", "0000fff1-0000-1000-8000-00805f9b34fb", DataToSend)
Catch
Log("Error during WriteData: " & LastException.Message)
End Try
pbReadData.Hide
End Sub
That error confirms it: java.lang.RuntimeException: Error writing data to.... This specific crash on the WriteData line happens when the Android GATT service returns false or throws an exception because the Bluetooth stack is busy or in an invalid state.
Since this is happening on a Sony device, you are hitting the GATT Serial Queue limit. Android can only handle one GATT operation at a time. Because you are calling RequestMtu, SetNotify, and WriteData in a single block, the Sony stack is still trying to process the MTU/Notification when the Write command arrives, causing the crash.
How to fix this in B4A
You need to implement a small delay between commands to give the Sony Bluetooth hardware time to clear its internal buffer.
In Android 9, the BluetoothGatt object often returns false or throws a RuntimeException if a second operation is attempted before the onDescriptorWrite (from SetNotify) or onMtuChanged callback has returned from the system.
On your Fairphone 6, the modern stack likely abstracts this away. On the Sony, you are manually colliding with the hardware state machine.