I am trying to covert the bytes into string what I am getting after reading from bluetooth device. Below is the code I am using, but it is not giving proper string. Output is like this
02-19 18:01:49.300: I/BluetoothReadService(17693): Message Read : ���8��1.04TTO��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
byte[] buffer = new byte[1024];
int bytes;
// Keep listening to the InputStream while connected
while (true)
{
try
{
// Read from the InputStream
bytes = mmInStream.read(buffer, 0, buffer.length);
String readMessage = null;
byte[] getBytes = null;
try {
readMessage = BitConverter.toString(buffer);
getBytes = BitConverter.getBytes(readMessage);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String s = new String(getBytes, "US-ASCII");
Log.i(TAG, "Message Read : "+readMessage +"ByteString"+s);
mHandler.obtainMessage(MainActivity.MESSAGE_READ).sendToTarget();
} catch (IOException e)
{
Log.e(TAG, "disconnected", e);
connectionLost();
break;
}
Please suggest what to do?