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