Gil Gil - 1 year ago 95
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

Answer Source

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();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download