Open JakeBuck opened 5 years ago
Hi there, thanks for reporting this! I don't like the proposed solution as it doesn't solve the issue itself, and may introduce other timing issues. Can you please verify what Android version you are running on? In addition, can you try adding a flush
command in closeSocket
before the close
itself? It seems that in earlier versions of Android flushing didn't really work with BluetoothSocket
s (https://stackoverflow.com/a/24969079), so this issue may be responsible for the behavior you are seeing.
I'm on Android 8.1.
I'm not well-versed with Android programming yet but adding "socket.getOutputStream().flush();" before "socket.close();" in "private void closeSocket(BluetoothSocket socket)" did not work. Not sure if that's what you were asking for, though. It already runs a flush when it tries to send the message and then it should flush again when the socket is closed if I'm interpreting things properly.
I came across an issue when running an ESP-WROOM-32 as a bluetooth serial bridge where the socket would close without transmitting data. I could sometimes get the data to send if I triggered the plugin multiple times very quickly, so I figured there was a timing issue. Downloaded your source, added
Before
in SettingReceiver.java and built it, works perfectly now. Not sure as to actual cause but thought you might want to know.