Skip to content

Commit a9a736d

Browse files
Still fixing arduino issue...
1 parent a99be11 commit a9a736d

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

btutillib/src/main/java/com/devpaul/bluetoothutillib/handlers/DefaultBluetoothHandler.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ public void handleMessage(Message message) {
2929
switch (message.what) {
3030
case MESSAGE_READ:
3131
byte[] readBuf = (byte[]) message.obj;
32-
String readMessage = new String(readBuf);
32+
//get how many bytes were actually read.
33+
int datalength = message.arg1;
34+
String readMessage = new String(readBuf, 0, datalength);
3335
if(readBuf.length > 0) {
3436
if(mListener != null)
3537
mListener.onBluetoothDataReceived(readBuf, readMessage);

btutillib/src/main/java/com/devpaul/bluetoothutillib/utils/BluetoothUtility.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,7 @@ public void run() {
742742
// Read from the InputStream
743743
bytes = mInputStream.read(buffer);
744744
// Send the obtained bytes to the UI activity
745+
//order is what, arg1, arg2, obj
745746
bluetoothHandler.obtainMessage(BluetoothHandler.MESSAGE_READ, bytes, -1, buffer)
746747
.sendToTarget();
747748
} catch (IOException e) {
@@ -757,7 +758,7 @@ public void run() {
757758
if(reader.ready()) {
758759
//read a single line.
759760
String message = reader.readLine();
760-
//don't use the regular buffer.
761+
//don't use the regular buffer.
761762
byte[] byteString = message.getBytes();
762763
bytes = byteString.length;
763764
bluetoothHandler.obtainMessage(BluetoothHandler.MESSAGE_READ, bytes, -1, byteString)

0 commit comments

Comments
 (0)