79126690

Date: 2024-10-25 17:12:50
Score: 2
Natty:
Report link

After different approaches, I found the issue may just the connections with the bluetooth device and the socket. I created an escape char in the data transmission to know when the stream is complete from the bluetooth device. Below works as expected.

               var sb = StringBuilder()
               inputStream.read().let {
                    if (it.toChar().toString() == "#") {
                        mHandler.obtainMessage(
                            HandlerConstant.MESSAGE_READ,
                            sb.toString()
                        ).sendToTarget()
                        sb.clear()
                    } else {
                        sb.append(it.toChar())
                    }
                }

Thanks for the help. This link helped me land on this approach Android Bluetooth InputStream read in realtime

Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Blacklisted phrase (1): This link
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: user22239162