I'm trying to receive data via bt on android device. When I'm sending bytes from terminal (for example 0x10 0x20 0x30 0x40) I don't get any response (the Toast does not pop-up). I wan't to get data in hexadecimal, not as a string. Here is the code from handler:
mHandler = new Handler() {
public void handleMessage(android.os.Message msg)
{if(msg.what == MESSAGE_READ){
try {
byte[] readBuf = (byte[]) msg.obj;
Toast.makeText(MainActivity.this, readBuf[0], Toast.LENGTH_SHORT).show();
} catch (IllegalArgumentException e) {
e.printStackTrace();
}
}
}
};
I'm using Android Studio 2.2.3 How to display received bytes in hex form?
Edit: afted using function byteToHexString() Toast pop up only when I'm sending data as ASCII characters, nothing happens while sending as hex. I can't debug it, because Android Studio can't see my device. Modified code in handler:
byte[] readBuf = (byte[]) msg.obj;
String readMessage = new String(readBuf, 0, msg.arg1);
String HexStr = null;
HexStr = byteToHexString(readBuf);
Toast.makeText(MainActivity.this,HexStr, Toast.LENGTH_SHORT).show();
Edit 2: I can receive numbers, but only from range 0x30-0x39 - numbers assigned to chars 1-9 in ASCII. It seems like code from handler executes only while receiving ASCII numbers