Gil Gil - 3 months ago 7
Android Question

Bluetooth barcode getInputStream()

I am using a bluetooth barcode reader to deliver text to an edit text. The problem is that it cuts the barcode text for about half the time and delivers me an incomplete text.

I am using the class "BluetoothSocket".
This is my reading code:

int bytes = socket.getInputStream().read(buffer);

message = message + new String(buffer, 0, bytes);

// Send the obtained bytes to the UI Activity MessagePoster(textView, message));

I am looking for a way to make the action of getInputStream() be longer


Something like this should work, just keep going until the string is the expected length. I'm assume the stream just keeps going.

InputStream stream = socket.getInputStream();
StringBuilder builder = new StringBuilder();
do {
    byte [] buffer = new byte[256];
    int bytes =;
    builder.append(new String(buffer, 0, bytes));
} while ((builder.length() < 10));
String completeStr = builder.toString();