Created
January 14, 2017 19:42
-
-
Save xlbruce/5978adc25c0c57980e6091a6d37c9c0c to your computer and use it in GitHub Desktop.
This snippet reads a message from a bluetooth device and converts it content into a String object
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void run() { | |
StringBuilder sb = new StringBuilder(); | |
while (true) { | |
try { | |
byte[] buffer = new byte[1024]; | |
int bytes; | |
int bytesRead = -1; | |
do { | |
bytes = mmInStream.read(buffer, bytesRead+1, 1); | |
bytesRead+=bytes; | |
} while(buffer[bytesRead] != '\n'); | |
Log.i("Log info:", new String( Arrays.copyOfRange(buffer, 0, bytesRead-1))); | |
sb = new StringBuilder(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment